From 818f833d04443d15c67fc301dbe06a739f22539f Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Fri, 12 Jan 2024 22:23:55 -0600 Subject: [PATCH] [Repository] Add null integer column support, instance_list notes migration, regenerate repositories (#3969) --- common/database/database_update_manifest.cpp | 11 + .../base/base_aa_ability_repository.h | 211 ++++-- .../base/base_aa_rank_effects_repository.h | 81 ++- .../base/base_aa_rank_prereqs_repository.h | 71 +- .../base/base_aa_ranks_repository.h | 91 ++- .../base/base_account_flags_repository.h | 71 +- .../base/base_account_ip_repository.h | 67 +- .../base/base_account_repository.h | 43 +- .../base/base_account_rewards_repository.h | 83 ++- .../base/base_adventure_details_repository.h | 125 +++- .../base/base_adventure_members_repository.h | 75 +- .../base/base_adventure_stats_repository.h | 147 +++- ...venture_template_entry_flavor_repository.h | 69 +- ...base_adventure_template_entry_repository.h | 75 +- .../base/base_adventure_template_repository.h | 299 +++++--- .../base/base_alternate_currency_repository.h | 63 +- .../repositories/base/base_auras_repository.h | 81 ++- .../base/base_base_data_repository.h | 139 +++- .../base/base_blocked_spells_repository.h | 131 +++- .../repositories/base/base_books_repository.h | 67 +- .../base/base_bug_reports_repository.h | 201 ++++-- .../repositories/base/base_bugs_repository.h | 121 +++- .../repositories/base/base_buyer_repository.h | 71 +- ...base_char_create_combinations_repository.h | 107 ++- ...char_create_point_allocations_repository.h | 179 +++-- .../base/base_char_recipe_list_repository.h | 65 +- .../base_character_activities_repository.h | 93 ++- .../base_character_alt_currency_repository.h | 19 +- ...character_alternate_abilities_repository.h | 25 +- .../base/base_character_auras_repository.h | 1 - .../base_character_bandolier_repository.h | 31 +- .../base/base_character_bind_repository.h | 43 +- .../base/base_character_buffs_repository.h | 55 +- .../base_character_corpse_items_repository.h | 239 ++++-- .../base/base_character_corpses_repository.h | 399 ++++++---- .../base/base_character_currency_repository.h | 103 ++- .../base/base_character_data_repository.h | 571 ++++++++------- .../base_character_disciplines_repository.h | 19 +- .../base_character_exp_modifiers_repository.h | 81 ++- ...character_expedition_lockouts_repository.h | 91 ++- ...se_character_inspect_messages_repository.h | 69 +- ...haracter_instance_safereturns_repository.h | 113 ++- .../base_character_item_recast_repository.h | 19 +- .../base_character_languages_repository.h | 19 +- ...haracter_leadership_abilities_repository.h | 19 +- .../base/base_character_material_repository.h | 43 +- .../base_character_memmed_spells_repository.h | 19 +- .../base_character_peqzone_flags_repository.h | 63 +- .../base_character_pet_buffs_repository.h | 7 +- .../base/base_character_pet_info_repository.h | 7 +- .../base_character_pet_inventory_repository.h | 1 - .../base_character_potionbelt_repository.h | 25 +- .../base/base_character_skills_repository.h | 19 +- .../base/base_character_spells_repository.h | 19 +- .../base_character_stats_record_repository.h | 223 +++++- .../base_character_task_timers_repository.h | 89 ++- .../base/base_character_tasks_repository.h | 95 ++- .../base/base_character_tribute_repository.h | 83 ++- ...se_chatchannel_reserved_names_repository.h | 61 +- .../base/base_chatchannels_repository.h | 67 +- .../base_command_subsettings_repository.h | 79 +- ...ed_shared_task_activity_state_repository.h | 75 +- ...completed_shared_task_members_repository.h | 77 +- .../base_completed_shared_tasks_repository.h | 77 +- .../base/base_completed_tasks_repository.h | 85 ++- .../base/base_content_flags_repository.h | 67 +- .../base/base_damageshieldtypes_repository.h | 75 +- .../base/base_data_buckets_repository.h | 101 ++- .../base/base_db_str_repository.h | 65 +- .../base/base_discord_webhooks_repository.h | 69 +- .../base/base_discovered_items_repository.h | 79 +- .../repositories/base/base_doors_repository.h | 209 ++++-- .../base_dynamic_zone_members_repository.h | 83 ++- .../base_dynamic_zone_templates_repository.h | 175 ++++- .../base/base_dynamic_zones_repository.h | 219 ++++-- .../base_expedition_lockouts_repository.h | 89 ++- .../base/base_expeditions_repository.h | 91 ++- .../base_faction_association_repository.h | 161 ++++- .../base/base_faction_base_data_repository.h | 71 +- .../base/base_faction_list_mod_repository.h | 79 +- .../base/base_faction_list_repository.h | 65 +- .../base/base_faction_values_repository.h | 67 +- .../base/base_fishing_repository.h | 81 ++- .../base/base_forage_repository.h | 77 +- .../base/base_friends_repository.h | 77 +- .../base/base_global_loot_repository.h | 93 ++- .../base/base_gm_ips_repository.h | 65 +- .../base/base_graveyard_repository.h | 95 ++- .../base/base_grid_entries_repository.h | 101 ++- .../repositories/base/base_grid_repository.h | 67 +- .../base/base_ground_spawns_repository.h | 161 ++++- .../base/base_group_id_repository.h | 67 +- .../base/base_group_leaders_repository.h | 77 +- .../base/base_guild_members_repository.h | 488 +++++++++++++ .../base/base_guild_ranks_repository.h | 169 ++--- .../base/base_guild_relations_repository.h | 77 +- .../base/base_guilds_repository.h | 95 ++- .../base/base_horses_repository.h | 79 +- .../base_instance_list_player_repository.h | 75 +- .../base/base_instance_list_repository.h | 135 +++- .../base/base_inventory_repository.h | 169 +++-- .../base_inventory_snapshots_repository.h | 177 +++-- .../base/base_ip_exemptions_repository.h | 65 +- .../base/base_item_tick_repository.h | 71 +- .../repositories/base/base_items_repository.h | 669 ++++++++++++++++- .../base/base_ldon_trap_entries_repository.h | 75 +- .../base_ldon_trap_templates_repository.h | 99 ++- .../base/base_level_exp_mods_repository.h | 77 +- .../base/base_lfguild_repository.h | 119 ++- .../base/base_login_accounts_repository.h | 83 ++- .../base/base_login_api_tokens_repository.h | 71 +- .../base_login_server_admins_repository.h | 81 ++- .../base_login_server_list_types_repository.h | 69 +- .../base_login_world_servers_repository.h | 85 ++- .../base/base_logsys_categories_repository.h | 1 - .../base/base_lootdrop_entries_repository.h | 141 +++- .../base/base_lootdrop_repository.h | 77 +- .../base/base_loottable_entries_repository.h | 107 ++- .../base/base_loottable_repository.h | 103 ++- .../repositories/base/base_mail_repository.h | 87 ++- .../base/base_merc_buffs_repository.h | 167 ++++- .../base/base_merchantlist_repository.h | 121 +++- .../base/base_merchantlist_temp_repository.h | 95 ++- .../repositories/base/base_mercs_repository.h | 243 +++++-- .../base/base_name_filter_repository.h | 63 +- .../base/base_npc_emotes_repository.h | 73 +- .../base_npc_faction_entries_repository.h | 81 ++- .../base/base_npc_faction_repository.h | 67 +- .../base_npc_scale_global_base_repository.h | 147 +++- ...se_npc_spells_effects_entries_repository.h | 93 ++- .../base/base_npc_spells_effects_repository.h | 77 +- .../base/base_npc_spells_entries_repository.h | 113 ++- .../base/base_npc_spells_repository.h | 185 +++-- .../base/base_npc_types_repository.h | 683 +++++++++++++----- .../base/base_npc_types_tint_repository.h | 285 +++++--- .../base/base_object_contents_repository.h | 137 +++- .../base/base_object_repository.h | 275 ++++--- ...se_perl_event_export_settings_repository.h | 73 +- .../base/base_petitions_repository.h | 109 ++- .../base_pets_beastlord_data_repository.h | 109 ++- ...ase_pets_equipmentset_entries_repository.h | 65 +- .../base/base_pets_equipmentset_repository.h | 65 +- .../repositories/base/base_pets_repository.h | 77 +- ...ase_player_event_log_settings_repository.h | 7 +- .../base/base_player_event_logs_repository.h | 43 +- .../base/base_player_titlesets_repository.h | 83 ++- .../base/base_quest_globals_repository.h | 71 +- .../base/base_raid_details_repository.h | 137 +++- .../base/base_raid_members_repository.h | 109 ++- .../base/base_reports_repository.h | 73 +- .../base/base_respawn_times_repository.h | 67 +- .../base/base_rule_sets_repository.h | 69 +- .../base/base_rule_values_repository.h | 73 +- .../base/base_saylink_repository.h | 63 +- .../base_server_scheduled_events_repository.h | 93 ++- ...se_shared_task_activity_state_repository.h | 75 +- ...ase_shared_task_dynamic_zones_repository.h | 75 +- .../base_shared_task_members_repository.h | 77 +- .../base/base_shared_tasks_repository.h | 77 +- .../base/base_skill_caps_repository.h | 99 ++- .../base/base_spawn2_disabled_repository.h | 71 +- .../base/base_spawn2_repository.h | 131 +++- .../base_spawn_condition_values_repository.h | 85 ++- .../base/base_spawn_conditions_repository.h | 81 ++- .../base/base_spawn_events_repository.h | 141 +++- .../base/base_spawnentry_repository.h | 77 +- .../base/base_spawngroup_repository.h | 121 +++- .../base/base_spell_buckets_repository.h | 91 ++- .../base/base_spell_globals_repository.h | 67 +- .../base/base_spells_new_repository.h | 577 ++++++++++++++- .../base/base_start_zones_repository.h | 145 +++- .../base/base_starting_items_repository.h | 101 ++- .../base/base_task_activities_repository.h | 67 +- .../repositories/base/base_tasks_repository.h | 91 ++- .../base/base_tasksets_repository.h | 75 +- .../base/base_timers_repository.h | 87 ++- .../base/base_titles_repository.h | 93 ++- .../base/base_trader_repository.h | 101 ++- ...ase_tradeskill_recipe_entries_repository.h | 75 +- .../base/base_tradeskill_recipe_repository.h | 149 +++- .../repositories/base/base_traps_repository.h | 145 +++- .../base/base_tribute_levels_repository.h | 91 ++- .../base/base_tributes_repository.h | 81 ++- .../base/base_variables_repository.h | 291 +++++--- ...base_veteran_reward_templates_repository.h | 93 ++- .../base/base_zone_points_repository.h | 191 +++-- .../repositories/base/base_zone_repository.h | 549 ++++++++++---- common/version.h | 2 +- .../generators/repository-generator.pl | 22 +- 189 files changed, 17218 insertions(+), 3604 deletions(-) create mode 100644 common/repositories/base/base_guild_members_repository.h diff --git a/common/database/database_update_manifest.cpp b/common/database/database_update_manifest.cpp index c30cfcb90..3ed90b625 100644 --- a/common/database/database_update_manifest.cpp +++ b/common/database/database_update_manifest.cpp @@ -5175,6 +5175,17 @@ ALTER TABLE `task_activities` )", .content_schema_update = true }, + ManifestEntry{ + .version = 9251, + .description = "2023_01_12_instance_list_notes.sql", + .check = "SHOW COLUMNS FROM `instance_list` LIKE 'notes'", + .condition = "empty", + .match = "", + .sql = R"( +ALTER TABLE `instance_list` + ADD COLUMN `notes` varchar(50) NOT NULL DEFAULT '' AFTER `never_expires`; +)", + }, // -- template; copy/paste this when you need to create a new entry // ManifestEntry{ diff --git a/common/repositories/base/base_aa_ability_repository.h b/common/repositories/base/base_aa_ability_repository.h index 293087871..62a8a97e3 100644 --- a/common/repositories/base/base_aa_ability_repository.h +++ b/common/repositories/base/base_aa_ability_repository.h @@ -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_AA_ABILITY_REPOSITORY_H @@ -33,6 +33,7 @@ public: int32_t first_rank_id; uint8_t enabled; int8_t reset_on_death; + int8_t auto_grant_enabled; }; static std::string PrimaryKey() @@ -57,6 +58,7 @@ public: "first_rank_id", "enabled", "reset_on_death", + "auto_grant_enabled", }; } @@ -77,6 +79,7 @@ public: "first_rank_id", "enabled", "reset_on_death", + "auto_grant_enabled", }; } @@ -117,20 +120,21 @@ public: { AaAbility e{}; - e.id = 0; - e.name = ""; - e.category = -1; - e.classes = 131070; - e.races = 65535; - e.drakkin_heritage = 127; - e.deities = 131071; - e.status = 0; - e.type = 0; - e.charges = 0; - e.grant_only = 0; - e.first_rank_id = -1; - e.enabled = 1; - e.reset_on_death = 0; + e.id = 0; + e.name = ""; + e.category = -1; + e.classes = 131070; + e.races = 65535; + e.drakkin_heritage = 127; + e.deities = 131071; + e.status = 0; + e.type = 0; + e.charges = 0; + e.grant_only = 0; + e.first_rank_id = -1; + e.enabled = 1; + e.reset_on_death = 0; + e.auto_grant_enabled = 0; return e; } @@ -156,8 +160,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), aa_ability_id ) ); @@ -166,20 +171,21 @@ public: if (results.RowCount() == 1) { AaAbility e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.name = row[1] ? row[1] : ""; - e.category = static_cast(atoi(row[2])); - e.classes = static_cast(atoi(row[3])); - e.races = static_cast(atoi(row[4])); - e.drakkin_heritage = static_cast(atoi(row[5])); - e.deities = static_cast(atoi(row[6])); - e.status = static_cast(atoi(row[7])); - e.type = static_cast(atoi(row[8])); - e.charges = static_cast(atoi(row[9])); - e.grant_only = static_cast(atoi(row[10])); - e.first_rank_id = static_cast(atoi(row[11])); - e.enabled = static_cast(strtoul(row[12], nullptr, 10)); - e.reset_on_death = static_cast(atoi(row[13])); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.name = row[1] ? row[1] : ""; + e.category = static_cast(atoi(row[2])); + e.classes = static_cast(atoi(row[3])); + e.races = static_cast(atoi(row[4])); + e.drakkin_heritage = static_cast(atoi(row[5])); + e.deities = static_cast(atoi(row[6])); + e.status = static_cast(atoi(row[7])); + e.type = static_cast(atoi(row[8])); + e.charges = static_cast(atoi(row[9])); + e.grant_only = static_cast(atoi(row[10])); + e.first_rank_id = static_cast(atoi(row[11])); + e.enabled = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 1; + e.reset_on_death = static_cast(atoi(row[13])); + e.auto_grant_enabled = static_cast(atoi(row[14])); return e; } @@ -227,6 +233,7 @@ public: v.push_back(columns[11] + " = " + std::to_string(e.first_rank_id)); v.push_back(columns[12] + " = " + std::to_string(e.enabled)); v.push_back(columns[13] + " = " + std::to_string(e.reset_on_death)); + v.push_back(columns[14] + " = " + std::to_string(e.auto_grant_enabled)); auto results = db.QueryDatabase( fmt::format( @@ -262,6 +269,7 @@ public: v.push_back(std::to_string(e.first_rank_id)); v.push_back(std::to_string(e.enabled)); v.push_back(std::to_string(e.reset_on_death)); + v.push_back(std::to_string(e.auto_grant_enabled)); auto results = db.QueryDatabase( fmt::format( @@ -305,6 +313,7 @@ public: v.push_back(std::to_string(e.first_rank_id)); v.push_back(std::to_string(e.enabled)); v.push_back(std::to_string(e.reset_on_death)); + v.push_back(std::to_string(e.auto_grant_enabled)); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } @@ -338,20 +347,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaAbility e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.name = row[1] ? row[1] : ""; - e.category = static_cast(atoi(row[2])); - e.classes = static_cast(atoi(row[3])); - e.races = static_cast(atoi(row[4])); - e.drakkin_heritage = static_cast(atoi(row[5])); - e.deities = static_cast(atoi(row[6])); - e.status = static_cast(atoi(row[7])); - e.type = static_cast(atoi(row[8])); - e.charges = static_cast(atoi(row[9])); - e.grant_only = static_cast(atoi(row[10])); - e.first_rank_id = static_cast(atoi(row[11])); - e.enabled = static_cast(strtoul(row[12], nullptr, 10)); - e.reset_on_death = static_cast(atoi(row[13])); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.name = row[1] ? row[1] : ""; + e.category = static_cast(atoi(row[2])); + e.classes = static_cast(atoi(row[3])); + e.races = static_cast(atoi(row[4])); + e.drakkin_heritage = static_cast(atoi(row[5])); + e.deities = static_cast(atoi(row[6])); + e.status = static_cast(atoi(row[7])); + e.type = static_cast(atoi(row[8])); + e.charges = static_cast(atoi(row[9])); + e.grant_only = static_cast(atoi(row[10])); + e.first_rank_id = static_cast(atoi(row[11])); + e.enabled = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 1; + e.reset_on_death = static_cast(atoi(row[13])); + e.auto_grant_enabled = static_cast(atoi(row[14])); all_entries.push_back(e); } @@ -376,20 +386,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaAbility e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.name = row[1] ? row[1] : ""; - e.category = static_cast(atoi(row[2])); - e.classes = static_cast(atoi(row[3])); - e.races = static_cast(atoi(row[4])); - e.drakkin_heritage = static_cast(atoi(row[5])); - e.deities = static_cast(atoi(row[6])); - e.status = static_cast(atoi(row[7])); - e.type = static_cast(atoi(row[8])); - e.charges = static_cast(atoi(row[9])); - e.grant_only = static_cast(atoi(row[10])); - e.first_rank_id = static_cast(atoi(row[11])); - e.enabled = static_cast(strtoul(row[12], nullptr, 10)); - e.reset_on_death = static_cast(atoi(row[13])); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.name = row[1] ? row[1] : ""; + e.category = static_cast(atoi(row[2])); + e.classes = static_cast(atoi(row[3])); + e.races = static_cast(atoi(row[4])); + e.drakkin_heritage = static_cast(atoi(row[5])); + e.deities = static_cast(atoi(row[6])); + e.status = static_cast(atoi(row[7])); + e.type = static_cast(atoi(row[8])); + e.charges = static_cast(atoi(row[9])); + e.grant_only = static_cast(atoi(row[10])); + e.first_rank_id = static_cast(atoi(row[11])); + e.enabled = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 1; + e.reset_on_death = static_cast(atoi(row[13])); + e.auto_grant_enabled = static_cast(atoi(row[14])); all_entries.push_back(e); } @@ -448,6 +459,90 @@ 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 AaAbility &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.category)); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.races)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.deities)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.grant_only)); + v.push_back(std::to_string(e.first_rank_id)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.reset_on_death)); + v.push_back(std::to_string(e.auto_grant_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 &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.name) + "'"); + v.push_back(std::to_string(e.category)); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.races)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.deities)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.grant_only)); + v.push_back(std::to_string(e.first_rank_id)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.reset_on_death)); + v.push_back(std::to_string(e.auto_grant_enabled)); + + 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_AA_ABILITY_REPOSITORY_H diff --git a/common/repositories/base/base_aa_rank_effects_repository.h b/common/repositories/base/base_aa_rank_effects_repository.h index b2f3b70cf..ee728bde0 100644 --- a/common/repositories/base/base_aa_rank_effects_repository.h +++ b/common/repositories/base/base_aa_rank_effects_repository.h @@ -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_AA_RANK_EFFECTS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), aa_rank_effects_id ) ); @@ -130,8 +131,8 @@ public: if (results.RowCount() == 1) { AaRankEffects e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.effect_id = static_cast(atoi(row[2])); e.base1 = static_cast(atoi(row[3])); e.base2 = static_cast(atoi(row[4])); @@ -266,8 +267,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRankEffects e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.effect_id = static_cast(atoi(row[2])); e.base1 = static_cast(atoi(row[3])); e.base2 = static_cast(atoi(row[4])); @@ -295,8 +296,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRankEffects e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.effect_id = static_cast(atoi(row[2])); e.base1 = static_cast(atoi(row[3])); e.base2 = static_cast(atoi(row[4])); @@ -358,6 +359,70 @@ 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 AaRankEffects &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.rank_id)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.effect_id)); + v.push_back(std::to_string(e.base1)); + v.push_back(std::to_string(e.base2)); + + 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.rank_id)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.effect_id)); + v.push_back(std::to_string(e.base1)); + v.push_back(std::to_string(e.base2)); + + 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_AA_RANK_EFFECTS_REPOSITORY_H diff --git a/common/repositories/base/base_aa_rank_prereqs_repository.h b/common/repositories/base/base_aa_rank_prereqs_repository.h index 0d00e2eea..86796b0e8 100644 --- a/common/repositories/base/base_aa_rank_prereqs_repository.h +++ b/common/repositories/base/base_aa_rank_prereqs_repository.h @@ -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_AA_RANK_PREREQS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), aa_rank_prereqs_id ) ); @@ -122,7 +123,7 @@ public: if (results.RowCount() == 1) { AaRankPrereqs e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.aa_id = static_cast(atoi(row[1])); e.points = static_cast(atoi(row[2])); @@ -250,7 +251,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRankPrereqs e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.aa_id = static_cast(atoi(row[1])); e.points = static_cast(atoi(row[2])); @@ -277,7 +278,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRankPrereqs e{}; - e.rank_id = static_cast(strtoul(row[0], nullptr, 10)); + e.rank_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.aa_id = static_cast(atoi(row[1])); e.points = static_cast(atoi(row[2])); @@ -338,6 +339,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 AaRankPrereqs &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.rank_id)); + v.push_back(std::to_string(e.aa_id)); + v.push_back(std::to_string(e.points)); + + 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.rank_id)); + v.push_back(std::to_string(e.aa_id)); + v.push_back(std::to_string(e.points)); + + 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_AA_RANK_PREREQS_REPOSITORY_H diff --git a/common/repositories/base/base_aa_ranks_repository.h b/common/repositories/base/base_aa_ranks_repository.h index d744fe731..717102055 100644 --- a/common/repositories/base/base_aa_ranks_repository.h +++ b/common/repositories/base/base_aa_ranks_repository.h @@ -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_AA_RANKS_REPOSITORY_H @@ -152,8 +152,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), aa_ranks_id ) ); @@ -162,7 +163,7 @@ public: if (results.RowCount() == 1) { AaRanks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.upper_hotkey_sid = static_cast(atoi(row[1])); e.lower_hotkey_sid = static_cast(atoi(row[2])); e.title_sid = static_cast(atoi(row[3])); @@ -330,7 +331,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRanks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.upper_hotkey_sid = static_cast(atoi(row[1])); e.lower_hotkey_sid = static_cast(atoi(row[2])); e.title_sid = static_cast(atoi(row[3])); @@ -367,7 +368,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AaRanks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.upper_hotkey_sid = static_cast(atoi(row[1])); e.lower_hotkey_sid = static_cast(atoi(row[2])); e.title_sid = static_cast(atoi(row[3])); @@ -438,6 +439,86 @@ 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 AaRanks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.upper_hotkey_sid)); + v.push_back(std::to_string(e.lower_hotkey_sid)); + v.push_back(std::to_string(e.title_sid)); + v.push_back(std::to_string(e.desc_sid)); + v.push_back(std::to_string(e.cost)); + v.push_back(std::to_string(e.level_req)); + v.push_back(std::to_string(e.spell)); + v.push_back(std::to_string(e.spell_type)); + v.push_back(std::to_string(e.recast_time)); + v.push_back(std::to_string(e.expansion)); + v.push_back(std::to_string(e.prev_id)); + v.push_back(std::to_string(e.next_id)); + + 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(std::to_string(e.upper_hotkey_sid)); + v.push_back(std::to_string(e.lower_hotkey_sid)); + v.push_back(std::to_string(e.title_sid)); + v.push_back(std::to_string(e.desc_sid)); + v.push_back(std::to_string(e.cost)); + v.push_back(std::to_string(e.level_req)); + v.push_back(std::to_string(e.spell)); + v.push_back(std::to_string(e.spell_type)); + v.push_back(std::to_string(e.recast_time)); + v.push_back(std::to_string(e.expansion)); + v.push_back(std::to_string(e.prev_id)); + v.push_back(std::to_string(e.next_id)); + + 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_AA_RANKS_REPOSITORY_H diff --git a/common/repositories/base/base_account_flags_repository.h b/common/repositories/base/base_account_flags_repository.h index 52deedc55..a40c0c3ef 100644 --- a/common/repositories/base/base_account_flags_repository.h +++ b/common/repositories/base/base_account_flags_repository.h @@ -6,7 +6,7 @@ * Any modifications to base repositories are to be made by the generator only * * @generator ./utils/scripts/generators/repository-generator.pl - * @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories + * @docs https://docs.eqemu.io/developer/repositories */ #ifndef EQEMU_BASE_ACCOUNT_FLAGS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), account_flags_id ) ); @@ -122,7 +123,7 @@ public: if (results.RowCount() == 1) { AccountFlags e{}; - e.p_accid = static_cast(strtoul(row[0], nullptr, 10)); + e.p_accid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.p_flag = row[1] ? row[1] : ""; e.p_value = row[2] ? row[2] : ""; @@ -250,7 +251,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AccountFlags e{}; - e.p_accid = static_cast(strtoul(row[0], nullptr, 10)); + e.p_accid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.p_flag = row[1] ? row[1] : ""; e.p_value = row[2] ? row[2] : ""; @@ -277,7 +278,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AccountFlags e{}; - e.p_accid = static_cast(strtoul(row[0], nullptr, 10)); + e.p_accid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.p_flag = row[1] ? row[1] : ""; e.p_value = row[2] ? row[2] : ""; @@ -338,6 +339,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 AccountFlags &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.p_accid)); + v.push_back("'" + Strings::Escape(e.p_flag) + "'"); + v.push_back("'" + Strings::Escape(e.p_value) + "'"); + + 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.p_accid)); + v.push_back("'" + Strings::Escape(e.p_flag) + "'"); + v.push_back("'" + Strings::Escape(e.p_value) + "'"); + + 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_ACCOUNT_FLAGS_REPOSITORY_H diff --git a/common/repositories/base/base_account_ip_repository.h b/common/repositories/base/base_account_ip_repository.h index 9b53cd5f2..f93d3fa08 100644 --- a/common/repositories/base/base_account_ip_repository.h +++ b/common/repositories/base/base_account_ip_repository.h @@ -6,7 +6,7 @@ * Any modifications to base repositories are to be made by the generator only * * @generator ./utils/scripts/generators/repository-generator.pl - * @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories + * @docs https://docs.eqemu.io/developer/repositories */ #ifndef EQEMU_BASE_ACCOUNT_IP_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), account_ip_id ) ); @@ -348,6 +349,68 @@ 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 AccountIp &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.accid)); + v.push_back("'" + Strings::Escape(e.ip) + "'"); + v.push_back(std::to_string(e.count)); + v.push_back("'" + Strings::Escape(e.lastused) + "'"); + + 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.accid)); + v.push_back("'" + Strings::Escape(e.ip) + "'"); + v.push_back(std::to_string(e.count)); + v.push_back("'" + Strings::Escape(e.lastused) + "'"); + + 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_ACCOUNT_IP_REPOSITORY_H diff --git a/common/repositories/base/base_account_repository.h b/common/repositories/base/base_account_repository.h index 208dfe6cf..6e24e8538 100644 --- a/common/repositories/base/base_account_repository.h +++ b/common/repositories/base/base_account_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseAccountRepository { public: struct Account { @@ -211,22 +210,22 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.charname = row[2] ? row[2] : ""; - e.sharedplat = static_cast(strtoul(row[3], nullptr, 10)); + e.sharedplat = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.password = row[4] ? row[4] : ""; e.status = static_cast(atoi(row[5])); e.ls_id = row[6] ? row[6] : ""; - e.lsaccount_id = static_cast(strtoul(row[7], nullptr, 10)); - e.gmspeed = static_cast(strtoul(row[8], nullptr, 10)); + e.lsaccount_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.gmspeed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.invulnerable = static_cast(atoi(row[9])); e.flymode = static_cast(atoi(row[10])); e.ignore_tells = static_cast(atoi(row[11])); - e.revoked = static_cast(strtoul(row[12], nullptr, 10)); - e.karma = static_cast(strtoul(row[13], nullptr, 10)); + e.revoked = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.karma = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.minilogin_ip = row[14] ? row[14] : ""; e.hideme = static_cast(atoi(row[15])); - e.rulesflag = static_cast(strtoul(row[16], nullptr, 10)); + e.rulesflag = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); - e.time_creation = static_cast(strtoul(row[18], nullptr, 10)); + e.time_creation = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; e.ban_reason = row[19] ? row[19] : ""; e.suspend_reason = row[20] ? row[20] : ""; e.crc_eqgame = row[21] ? row[21] : ""; @@ -422,22 +421,22 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.charname = row[2] ? row[2] : ""; - e.sharedplat = static_cast(strtoul(row[3], nullptr, 10)); + e.sharedplat = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.password = row[4] ? row[4] : ""; e.status = static_cast(atoi(row[5])); e.ls_id = row[6] ? row[6] : ""; - e.lsaccount_id = static_cast(strtoul(row[7], nullptr, 10)); - e.gmspeed = static_cast(strtoul(row[8], nullptr, 10)); + e.lsaccount_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.gmspeed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.invulnerable = static_cast(atoi(row[9])); e.flymode = static_cast(atoi(row[10])); e.ignore_tells = static_cast(atoi(row[11])); - e.revoked = static_cast(strtoul(row[12], nullptr, 10)); - e.karma = static_cast(strtoul(row[13], nullptr, 10)); + e.revoked = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.karma = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.minilogin_ip = row[14] ? row[14] : ""; e.hideme = static_cast(atoi(row[15])); - e.rulesflag = static_cast(strtoul(row[16], nullptr, 10)); + e.rulesflag = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); - e.time_creation = static_cast(strtoul(row[18], nullptr, 10)); + e.time_creation = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; e.ban_reason = row[19] ? row[19] : ""; e.suspend_reason = row[20] ? row[20] : ""; e.crc_eqgame = row[21] ? row[21] : ""; @@ -470,22 +469,22 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.charname = row[2] ? row[2] : ""; - e.sharedplat = static_cast(strtoul(row[3], nullptr, 10)); + e.sharedplat = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.password = row[4] ? row[4] : ""; e.status = static_cast(atoi(row[5])); e.ls_id = row[6] ? row[6] : ""; - e.lsaccount_id = static_cast(strtoul(row[7], nullptr, 10)); - e.gmspeed = static_cast(strtoul(row[8], nullptr, 10)); + e.lsaccount_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.gmspeed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.invulnerable = static_cast(atoi(row[9])); e.flymode = static_cast(atoi(row[10])); e.ignore_tells = static_cast(atoi(row[11])); - e.revoked = static_cast(strtoul(row[12], nullptr, 10)); - e.karma = static_cast(strtoul(row[13], nullptr, 10)); + e.revoked = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.karma = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.minilogin_ip = row[14] ? row[14] : ""; e.hideme = static_cast(atoi(row[15])); - e.rulesflag = static_cast(strtoul(row[16], nullptr, 10)); + e.rulesflag = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.suspendeduntil = strtoll(row[17] ? row[17] : "-1", nullptr, 10); - e.time_creation = static_cast(strtoul(row[18], nullptr, 10)); + e.time_creation = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; e.ban_reason = row[19] ? row[19] : ""; e.suspend_reason = row[20] ? row[20] : ""; e.crc_eqgame = row[21] ? row[21] : ""; diff --git a/common/repositories/base/base_account_rewards_repository.h b/common/repositories/base/base_account_rewards_repository.h index 008a2b165..dc97053fa 100644 --- a/common/repositories/base/base_account_rewards_repository.h +++ b/common/repositories/base/base_account_rewards_repository.h @@ -6,7 +6,7 @@ * Any modifications to base repositories are to be made by the generator only * * @generator ./utils/scripts/generators/repository-generator.pl - * @docs https://eqemu.gitbook.io/server/in-development/developer-area/repositories + * @docs https://docs.eqemu.io/developer/repositories */ #ifndef EQEMU_BASE_ACCOUNT_REWARDS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), account_rewards_id ) ); @@ -122,9 +123,9 @@ public: if (results.RowCount() == 1) { AccountRewards e{}; - e.account_id = static_cast(strtoul(row[0], nullptr, 10)); - e.reward_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.account_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.reward_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -250,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AccountRewards e{}; - e.account_id = static_cast(strtoul(row[0], nullptr, 10)); - e.reward_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.account_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.reward_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -277,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AccountRewards e{}; - e.account_id = static_cast(strtoul(row[0], nullptr, 10)); - e.reward_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.account_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.reward_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -338,6 +339,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 AccountRewards &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.account_id)); + v.push_back(std::to_string(e.reward_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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.account_id)); + v.push_back(std::to_string(e.reward_id)); + v.push_back(std::to_string(e.amount)); + + 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_ACCOUNT_REWARDS_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_details_repository.h b/common/repositories/base/base_adventure_details_repository.h index e82accdef..009c253f5 100644 --- a/common/repositories/base/base_adventure_details_repository.h +++ b/common/repositories/base/base_adventure_details_repository.h @@ -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_ADVENTURE_DETAILS_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_details_id ) ); @@ -146,15 +147,15 @@ public: if (results.RowCount() == 1) { AdventureDetails e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.adventure_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.adventure_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[2])); - e.count = static_cast(strtoul(row[3], nullptr, 10)); - e.assassinate_count = static_cast(strtoul(row[4], nullptr, 10)); - e.status = static_cast(strtoul(row[5], nullptr, 10)); - e.time_created = static_cast(strtoul(row[6], nullptr, 10)); - e.time_zoned = static_cast(strtoul(row[7], nullptr, 10)); - e.time_completed = static_cast(strtoul(row[8], nullptr, 10)); + e.count = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.assassinate_count = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.time_created = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.time_zoned = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.time_completed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; return e; } @@ -297,15 +298,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureDetails e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.adventure_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.adventure_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[2])); - e.count = static_cast(strtoul(row[3], nullptr, 10)); - e.assassinate_count = static_cast(strtoul(row[4], nullptr, 10)); - e.status = static_cast(strtoul(row[5], nullptr, 10)); - e.time_created = static_cast(strtoul(row[6], nullptr, 10)); - e.time_zoned = static_cast(strtoul(row[7], nullptr, 10)); - e.time_completed = static_cast(strtoul(row[8], nullptr, 10)); + e.count = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.assassinate_count = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.time_created = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.time_zoned = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.time_completed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -330,15 +331,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureDetails e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.adventure_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.adventure_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[2])); - e.count = static_cast(strtoul(row[3], nullptr, 10)); - e.assassinate_count = static_cast(strtoul(row[4], nullptr, 10)); - e.status = static_cast(strtoul(row[5], nullptr, 10)); - e.time_created = static_cast(strtoul(row[6], nullptr, 10)); - e.time_zoned = static_cast(strtoul(row[7], nullptr, 10)); - e.time_completed = static_cast(strtoul(row[8], nullptr, 10)); + e.count = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.assassinate_count = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.time_created = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.time_zoned = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.time_completed = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -397,6 +398,78 @@ 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 AdventureDetails &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.adventure_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.count)); + v.push_back(std::to_string(e.assassinate_count)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.time_created)); + v.push_back(std::to_string(e.time_zoned)); + v.push_back(std::to_string(e.time_completed)); + + 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(std::to_string(e.adventure_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.count)); + v.push_back(std::to_string(e.assassinate_count)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.time_created)); + v.push_back(std::to_string(e.time_zoned)); + v.push_back(std::to_string(e.time_completed)); + + 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_ADVENTURE_DETAILS_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_members_repository.h b/common/repositories/base/base_adventure_members_repository.h index 1abf23b5b..4b78079d8 100644 --- a/common/repositories/base/base_adventure_members_repository.h +++ b/common/repositories/base/base_adventure_members_repository.h @@ -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_ADVENTURE_MEMBERS_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_members_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { AdventureMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 AdventureMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.charid)); + + 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(std::to_string(e.charid)); + + 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_ADVENTURE_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_stats_repository.h b/common/repositories/base/base_adventure_stats_repository.h index 5a25d5126..3e95ca694 100644 --- a/common/repositories/base/base_adventure_stats_repository.h +++ b/common/repositories/base/base_adventure_stats_repository.h @@ -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_ADVENTURE_STATS_REPOSITORY_H @@ -144,8 +144,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_stats_id ) ); @@ -154,17 +155,17 @@ public: if (results.RowCount() == 1) { AdventureStats e{}; - e.player_id = static_cast(strtoul(row[0], nullptr, 10)); - e.guk_wins = static_cast(strtoul(row[1], nullptr, 10)); - e.mir_wins = static_cast(strtoul(row[2], nullptr, 10)); - e.mmc_wins = static_cast(strtoul(row[3], nullptr, 10)); - e.ruj_wins = static_cast(strtoul(row[4], nullptr, 10)); - e.tak_wins = static_cast(strtoul(row[5], nullptr, 10)); - e.guk_losses = static_cast(strtoul(row[6], nullptr, 10)); - e.mir_losses = static_cast(strtoul(row[7], nullptr, 10)); - e.mmc_losses = static_cast(strtoul(row[8], nullptr, 10)); - e.ruj_losses = static_cast(strtoul(row[9], nullptr, 10)); - e.tak_losses = static_cast(strtoul(row[10], nullptr, 10)); + e.player_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guk_wins = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.mir_wins = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.mmc_wins = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.ruj_wins = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.tak_wins = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.guk_losses = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.mir_losses = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.mmc_losses = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.ruj_losses = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.tak_losses = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; return e; } @@ -314,17 +315,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureStats e{}; - e.player_id = static_cast(strtoul(row[0], nullptr, 10)); - e.guk_wins = static_cast(strtoul(row[1], nullptr, 10)); - e.mir_wins = static_cast(strtoul(row[2], nullptr, 10)); - e.mmc_wins = static_cast(strtoul(row[3], nullptr, 10)); - e.ruj_wins = static_cast(strtoul(row[4], nullptr, 10)); - e.tak_wins = static_cast(strtoul(row[5], nullptr, 10)); - e.guk_losses = static_cast(strtoul(row[6], nullptr, 10)); - e.mir_losses = static_cast(strtoul(row[7], nullptr, 10)); - e.mmc_losses = static_cast(strtoul(row[8], nullptr, 10)); - e.ruj_losses = static_cast(strtoul(row[9], nullptr, 10)); - e.tak_losses = static_cast(strtoul(row[10], nullptr, 10)); + e.player_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guk_wins = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.mir_wins = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.mmc_wins = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.ruj_wins = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.tak_wins = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.guk_losses = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.mir_losses = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.mmc_losses = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.ruj_losses = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.tak_losses = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -349,17 +350,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureStats e{}; - e.player_id = static_cast(strtoul(row[0], nullptr, 10)); - e.guk_wins = static_cast(strtoul(row[1], nullptr, 10)); - e.mir_wins = static_cast(strtoul(row[2], nullptr, 10)); - e.mmc_wins = static_cast(strtoul(row[3], nullptr, 10)); - e.ruj_wins = static_cast(strtoul(row[4], nullptr, 10)); - e.tak_wins = static_cast(strtoul(row[5], nullptr, 10)); - e.guk_losses = static_cast(strtoul(row[6], nullptr, 10)); - e.mir_losses = static_cast(strtoul(row[7], nullptr, 10)); - e.mmc_losses = static_cast(strtoul(row[8], nullptr, 10)); - e.ruj_losses = static_cast(strtoul(row[9], nullptr, 10)); - e.tak_losses = static_cast(strtoul(row[10], nullptr, 10)); + e.player_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guk_wins = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.mir_wins = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.mmc_wins = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.ruj_wins = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.tak_wins = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.guk_losses = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.mir_losses = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.mmc_losses = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.ruj_losses = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.tak_losses = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -418,6 +419,82 @@ 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 AdventureStats &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.player_id)); + v.push_back(std::to_string(e.guk_wins)); + v.push_back(std::to_string(e.mir_wins)); + v.push_back(std::to_string(e.mmc_wins)); + v.push_back(std::to_string(e.ruj_wins)); + v.push_back(std::to_string(e.tak_wins)); + v.push_back(std::to_string(e.guk_losses)); + v.push_back(std::to_string(e.mir_losses)); + v.push_back(std::to_string(e.mmc_losses)); + v.push_back(std::to_string(e.ruj_losses)); + v.push_back(std::to_string(e.tak_losses)); + + 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.player_id)); + v.push_back(std::to_string(e.guk_wins)); + v.push_back(std::to_string(e.mir_wins)); + v.push_back(std::to_string(e.mmc_wins)); + v.push_back(std::to_string(e.ruj_wins)); + v.push_back(std::to_string(e.tak_wins)); + v.push_back(std::to_string(e.guk_losses)); + v.push_back(std::to_string(e.mir_losses)); + v.push_back(std::to_string(e.mmc_losses)); + v.push_back(std::to_string(e.ruj_losses)); + v.push_back(std::to_string(e.tak_losses)); + + 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_ADVENTURE_STATS_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_template_entry_flavor_repository.h b/common/repositories/base/base_adventure_template_entry_flavor_repository.h index 0507f7e85..118124560 100644 --- a/common/repositories/base/base_adventure_template_entry_flavor_repository.h +++ b/common/repositories/base/base_adventure_template_entry_flavor_repository.h @@ -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_ADVENTURE_TEMPLATE_ENTRY_FLAVOR_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_template_entry_flavor_id ) ); @@ -118,7 +119,7 @@ public: if (results.RowCount() == 1) { AdventureTemplateEntryFlavor e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.text = row[1] ? row[1] : ""; return e; @@ -242,7 +243,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplateEntryFlavor e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.text = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -268,7 +269,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplateEntryFlavor e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.text = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -328,6 +329,64 @@ 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 AdventureTemplateEntryFlavor &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.text) + "'"); + + 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.text) + "'"); + + 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_ADVENTURE_TEMPLATE_ENTRY_FLAVOR_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_template_entry_repository.h b/common/repositories/base/base_adventure_template_entry_repository.h index aad89b1d3..6c885ffb1 100644 --- a/common/repositories/base/base_adventure_template_entry_repository.h +++ b/common/repositories/base/base_adventure_template_entry_repository.h @@ -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_ADVENTURE_TEMPLATE_ENTRY_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_template_entry_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { AdventureTemplateEntry e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.template_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.template_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplateEntry e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.template_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.template_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplateEntry e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.template_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.template_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 AdventureTemplateEntry &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.template_id)); + + 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(std::to_string(e.template_id)); + + 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_ADVENTURE_TEMPLATE_ENTRY_REPOSITORY_H diff --git a/common/repositories/base/base_adventure_template_repository.h b/common/repositories/base/base_adventure_template_repository.h index ce6540ce2..c0c97e749 100644 --- a/common/repositories/base/base_adventure_template_repository.h +++ b/common/repositories/base/base_adventure_template_repository.h @@ -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_ADVENTURE_TEMPLATE_REPOSITORY_H @@ -232,8 +232,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), adventure_template_id ) ); @@ -242,38 +243,38 @@ public: if (results.RowCount() == 1) { AdventureTemplate e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.zone_version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_hard = static_cast(strtoul(row[3], nullptr, 10)); - e.is_raid = static_cast(strtoul(row[4], nullptr, 10)); - e.min_level = static_cast(strtoul(row[5], nullptr, 10)); - e.max_level = static_cast(strtoul(row[6], nullptr, 10)); - e.type = static_cast(strtoul(row[7], nullptr, 10)); - e.type_data = static_cast(strtoul(row[8], nullptr, 10)); - e.type_count = static_cast(strtoul(row[9], nullptr, 10)); - e.assa_x = strtof(row[10], nullptr); - e.assa_y = strtof(row[11], nullptr); - e.assa_z = strtof(row[12], nullptr); - e.assa_h = strtof(row[13], nullptr); + e.zone_version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_hard = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.is_raid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_level = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; + e.max_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 65; + e.type = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.type_data = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.type_count = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.assa_x = row[10] ? strtof(row[10], nullptr) : 0; + e.assa_y = row[11] ? strtof(row[11], nullptr) : 0; + e.assa_z = row[12] ? strtof(row[12], nullptr) : 0; + e.assa_h = row[13] ? strtof(row[13], nullptr) : 0; e.text = row[14] ? row[14] : ""; - e.duration = static_cast(strtoul(row[15], nullptr, 10)); - e.zone_in_time = static_cast(strtoul(row[16], nullptr, 10)); - e.win_points = static_cast(strtoul(row[17], nullptr, 10)); - e.lose_points = static_cast(strtoul(row[18], nullptr, 10)); - e.theme = static_cast(strtoul(row[19], nullptr, 10)); - e.zone_in_zone_id = static_cast(strtoul(row[20], nullptr, 10)); - e.zone_in_x = strtof(row[21], nullptr); - e.zone_in_y = strtof(row[22], nullptr); + e.duration = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 7200; + e.zone_in_time = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1800; + e.win_points = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.lose_points = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.theme = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.zone_in_zone_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.zone_in_x = row[21] ? strtof(row[21], nullptr) : 0; + e.zone_in_y = row[22] ? strtof(row[22], nullptr) : 0; e.zone_in_object_id = static_cast(atoi(row[23])); - e.dest_x = strtof(row[24], nullptr); - e.dest_y = strtof(row[25], nullptr); - e.dest_z = strtof(row[26], nullptr); - e.dest_h = strtof(row[27], nullptr); - e.graveyard_zone_id = static_cast(strtoul(row[28], nullptr, 10)); - e.graveyard_x = strtof(row[29], nullptr); - e.graveyard_y = strtof(row[30], nullptr); - e.graveyard_z = strtof(row[31], nullptr); + e.dest_x = row[24] ? strtof(row[24], nullptr) : 0; + e.dest_y = row[25] ? strtof(row[25], nullptr) : 0; + e.dest_z = row[26] ? strtof(row[26], nullptr) : 0; + e.dest_h = row[27] ? strtof(row[27], nullptr) : 0; + e.graveyard_zone_id = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.graveyard_x = row[29] ? strtof(row[29], nullptr) : 0; + e.graveyard_y = row[30] ? strtof(row[30], nullptr) : 0; + e.graveyard_z = row[31] ? strtof(row[31], nullptr) : 0; return e; } @@ -489,38 +490,38 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplate e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.zone_version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_hard = static_cast(strtoul(row[3], nullptr, 10)); - e.is_raid = static_cast(strtoul(row[4], nullptr, 10)); - e.min_level = static_cast(strtoul(row[5], nullptr, 10)); - e.max_level = static_cast(strtoul(row[6], nullptr, 10)); - e.type = static_cast(strtoul(row[7], nullptr, 10)); - e.type_data = static_cast(strtoul(row[8], nullptr, 10)); - e.type_count = static_cast(strtoul(row[9], nullptr, 10)); - e.assa_x = strtof(row[10], nullptr); - e.assa_y = strtof(row[11], nullptr); - e.assa_z = strtof(row[12], nullptr); - e.assa_h = strtof(row[13], nullptr); + e.zone_version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_hard = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.is_raid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_level = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; + e.max_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 65; + e.type = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.type_data = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.type_count = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.assa_x = row[10] ? strtof(row[10], nullptr) : 0; + e.assa_y = row[11] ? strtof(row[11], nullptr) : 0; + e.assa_z = row[12] ? strtof(row[12], nullptr) : 0; + e.assa_h = row[13] ? strtof(row[13], nullptr) : 0; e.text = row[14] ? row[14] : ""; - e.duration = static_cast(strtoul(row[15], nullptr, 10)); - e.zone_in_time = static_cast(strtoul(row[16], nullptr, 10)); - e.win_points = static_cast(strtoul(row[17], nullptr, 10)); - e.lose_points = static_cast(strtoul(row[18], nullptr, 10)); - e.theme = static_cast(strtoul(row[19], nullptr, 10)); - e.zone_in_zone_id = static_cast(strtoul(row[20], nullptr, 10)); - e.zone_in_x = strtof(row[21], nullptr); - e.zone_in_y = strtof(row[22], nullptr); + e.duration = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 7200; + e.zone_in_time = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1800; + e.win_points = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.lose_points = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.theme = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.zone_in_zone_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.zone_in_x = row[21] ? strtof(row[21], nullptr) : 0; + e.zone_in_y = row[22] ? strtof(row[22], nullptr) : 0; e.zone_in_object_id = static_cast(atoi(row[23])); - e.dest_x = strtof(row[24], nullptr); - e.dest_y = strtof(row[25], nullptr); - e.dest_z = strtof(row[26], nullptr); - e.dest_h = strtof(row[27], nullptr); - e.graveyard_zone_id = static_cast(strtoul(row[28], nullptr, 10)); - e.graveyard_x = strtof(row[29], nullptr); - e.graveyard_y = strtof(row[30], nullptr); - e.graveyard_z = strtof(row[31], nullptr); + e.dest_x = row[24] ? strtof(row[24], nullptr) : 0; + e.dest_y = row[25] ? strtof(row[25], nullptr) : 0; + e.dest_z = row[26] ? strtof(row[26], nullptr) : 0; + e.dest_h = row[27] ? strtof(row[27], nullptr) : 0; + e.graveyard_zone_id = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.graveyard_x = row[29] ? strtof(row[29], nullptr) : 0; + e.graveyard_y = row[30] ? strtof(row[30], nullptr) : 0; + e.graveyard_z = row[31] ? strtof(row[31], nullptr) : 0; all_entries.push_back(e); } @@ -545,38 +546,38 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { AdventureTemplate e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.zone_version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_hard = static_cast(strtoul(row[3], nullptr, 10)); - e.is_raid = static_cast(strtoul(row[4], nullptr, 10)); - e.min_level = static_cast(strtoul(row[5], nullptr, 10)); - e.max_level = static_cast(strtoul(row[6], nullptr, 10)); - e.type = static_cast(strtoul(row[7], nullptr, 10)); - e.type_data = static_cast(strtoul(row[8], nullptr, 10)); - e.type_count = static_cast(strtoul(row[9], nullptr, 10)); - e.assa_x = strtof(row[10], nullptr); - e.assa_y = strtof(row[11], nullptr); - e.assa_z = strtof(row[12], nullptr); - e.assa_h = strtof(row[13], nullptr); + e.zone_version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_hard = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.is_raid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_level = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; + e.max_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 65; + e.type = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.type_data = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.type_count = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.assa_x = row[10] ? strtof(row[10], nullptr) : 0; + e.assa_y = row[11] ? strtof(row[11], nullptr) : 0; + e.assa_z = row[12] ? strtof(row[12], nullptr) : 0; + e.assa_h = row[13] ? strtof(row[13], nullptr) : 0; e.text = row[14] ? row[14] : ""; - e.duration = static_cast(strtoul(row[15], nullptr, 10)); - e.zone_in_time = static_cast(strtoul(row[16], nullptr, 10)); - e.win_points = static_cast(strtoul(row[17], nullptr, 10)); - e.lose_points = static_cast(strtoul(row[18], nullptr, 10)); - e.theme = static_cast(strtoul(row[19], nullptr, 10)); - e.zone_in_zone_id = static_cast(strtoul(row[20], nullptr, 10)); - e.zone_in_x = strtof(row[21], nullptr); - e.zone_in_y = strtof(row[22], nullptr); + e.duration = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 7200; + e.zone_in_time = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1800; + e.win_points = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.lose_points = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.theme = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.zone_in_zone_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.zone_in_x = row[21] ? strtof(row[21], nullptr) : 0; + e.zone_in_y = row[22] ? strtof(row[22], nullptr) : 0; e.zone_in_object_id = static_cast(atoi(row[23])); - e.dest_x = strtof(row[24], nullptr); - e.dest_y = strtof(row[25], nullptr); - e.dest_z = strtof(row[26], nullptr); - e.dest_h = strtof(row[27], nullptr); - e.graveyard_zone_id = static_cast(strtoul(row[28], nullptr, 10)); - e.graveyard_x = strtof(row[29], nullptr); - e.graveyard_y = strtof(row[30], nullptr); - e.graveyard_z = strtof(row[31], nullptr); + e.dest_x = row[24] ? strtof(row[24], nullptr) : 0; + e.dest_y = row[25] ? strtof(row[25], nullptr) : 0; + e.dest_z = row[26] ? strtof(row[26], nullptr) : 0; + e.dest_h = row[27] ? strtof(row[27], nullptr) : 0; + e.graveyard_zone_id = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.graveyard_x = row[29] ? strtof(row[29], nullptr) : 0; + e.graveyard_y = row[30] ? strtof(row[30], nullptr) : 0; + e.graveyard_z = row[31] ? strtof(row[31], nullptr) : 0; all_entries.push_back(e); } @@ -635,6 +636,126 @@ 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 AdventureTemplate &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.zone_version)); + v.push_back(std::to_string(e.is_hard)); + v.push_back(std::to_string(e.is_raid)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.type_data)); + v.push_back(std::to_string(e.type_count)); + v.push_back(std::to_string(e.assa_x)); + v.push_back(std::to_string(e.assa_y)); + v.push_back(std::to_string(e.assa_z)); + v.push_back(std::to_string(e.assa_h)); + v.push_back("'" + Strings::Escape(e.text) + "'"); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.zone_in_time)); + v.push_back(std::to_string(e.win_points)); + v.push_back(std::to_string(e.lose_points)); + v.push_back(std::to_string(e.theme)); + v.push_back(std::to_string(e.zone_in_zone_id)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_object_id)); + v.push_back(std::to_string(e.dest_x)); + v.push_back(std::to_string(e.dest_y)); + v.push_back(std::to_string(e.dest_z)); + v.push_back(std::to_string(e.dest_h)); + v.push_back(std::to_string(e.graveyard_zone_id)); + v.push_back(std::to_string(e.graveyard_x)); + v.push_back(std::to_string(e.graveyard_y)); + v.push_back(std::to_string(e.graveyard_z)); + v.push_back(std::to_string(e.graveyard_radius)); + + 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.zone_version)); + v.push_back(std::to_string(e.is_hard)); + v.push_back(std::to_string(e.is_raid)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.type_data)); + v.push_back(std::to_string(e.type_count)); + v.push_back(std::to_string(e.assa_x)); + v.push_back(std::to_string(e.assa_y)); + v.push_back(std::to_string(e.assa_z)); + v.push_back(std::to_string(e.assa_h)); + v.push_back("'" + Strings::Escape(e.text) + "'"); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.zone_in_time)); + v.push_back(std::to_string(e.win_points)); + v.push_back(std::to_string(e.lose_points)); + v.push_back(std::to_string(e.theme)); + v.push_back(std::to_string(e.zone_in_zone_id)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_object_id)); + v.push_back(std::to_string(e.dest_x)); + v.push_back(std::to_string(e.dest_y)); + v.push_back(std::to_string(e.dest_z)); + v.push_back(std::to_string(e.dest_h)); + v.push_back(std::to_string(e.graveyard_zone_id)); + v.push_back(std::to_string(e.graveyard_x)); + v.push_back(std::to_string(e.graveyard_y)); + v.push_back(std::to_string(e.graveyard_z)); + v.push_back(std::to_string(e.graveyard_radius)); + + 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_ADVENTURE_TEMPLATE_REPOSITORY_H diff --git a/common/repositories/base/base_alternate_currency_repository.h b/common/repositories/base/base_alternate_currency_repository.h index 10798b859..362efa2ba 100644 --- a/common/repositories/base/base_alternate_currency_repository.h +++ b/common/repositories/base/base_alternate_currency_repository.h @@ -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_ALTERNATE_CURRENCY_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), alternate_currency_id ) ); @@ -328,6 +329,64 @@ 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 AlternateCurrency &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.item_id)); + + 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(std::to_string(e.item_id)); + + 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_ALTERNATE_CURRENCY_REPOSITORY_H diff --git a/common/repositories/base/base_auras_repository.h b/common/repositories/base/base_auras_repository.h index e527fa8aa..e363fb8ca 100644 --- a/common/repositories/base/base_auras_repository.h +++ b/common/repositories/base/base_auras_repository.h @@ -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_AURAS_REPOSITORY_H @@ -144,8 +144,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), auras_id ) ); @@ -418,6 +419,82 @@ 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 Auras &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.npc_type)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.distance)); + v.push_back(std::to_string(e.aura_type)); + v.push_back(std::to_string(e.spawn_type)); + v.push_back(std::to_string(e.movement)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.cast_time)); + + 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.type)); + v.push_back(std::to_string(e.npc_type)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.distance)); + v.push_back(std::to_string(e.aura_type)); + v.push_back(std::to_string(e.spawn_type)); + v.push_back(std::to_string(e.movement)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.cast_time)); + + 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_AURAS_REPOSITORY_H diff --git a/common/repositories/base/base_base_data_repository.h b/common/repositories/base/base_base_data_repository.h index 8b41d99a8..ef75bdf31 100644 --- a/common/repositories/base/base_base_data_repository.h +++ b/common/repositories/base/base_base_data_repository.h @@ -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_BASE_DATA_REPOSITORY_H @@ -140,8 +140,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), base_data_id ) ); @@ -150,16 +151,16 @@ public: if (results.RowCount() == 1) { BaseData e{}; - e.level = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.hp = strtod(row[2], nullptr); - e.mana = strtod(row[3], nullptr); - e.end = strtod(row[4], nullptr); - e.unk1 = strtod(row[5], nullptr); - e.unk2 = strtod(row[6], nullptr); - e.hp_fac = strtod(row[7], nullptr); - e.mana_fac = strtod(row[8], nullptr); - e.end_fac = strtod(row[9], nullptr); + e.level = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.hp = row[2] ? strtod(row[2], nullptr) : 0; + e.mana = row[3] ? strtod(row[3], nullptr) : 0; + e.end = row[4] ? strtod(row[4], nullptr) : 0; + e.unk1 = row[5] ? strtod(row[5], nullptr) : 0; + e.unk2 = row[6] ? strtod(row[6], nullptr) : 0; + e.hp_fac = row[7] ? strtod(row[7], nullptr) : 0; + e.mana_fac = row[8] ? strtod(row[8], nullptr) : 0; + e.end_fac = row[9] ? strtod(row[9], nullptr) : 0; return e; } @@ -306,16 +307,16 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { BaseData e{}; - e.level = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.hp = strtod(row[2], nullptr); - e.mana = strtod(row[3], nullptr); - e.end = strtod(row[4], nullptr); - e.unk1 = strtod(row[5], nullptr); - e.unk2 = strtod(row[6], nullptr); - e.hp_fac = strtod(row[7], nullptr); - e.mana_fac = strtod(row[8], nullptr); - e.end_fac = strtod(row[9], nullptr); + e.level = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.hp = row[2] ? strtod(row[2], nullptr) : 0; + e.mana = row[3] ? strtod(row[3], nullptr) : 0; + e.end = row[4] ? strtod(row[4], nullptr) : 0; + e.unk1 = row[5] ? strtod(row[5], nullptr) : 0; + e.unk2 = row[6] ? strtod(row[6], nullptr) : 0; + e.hp_fac = row[7] ? strtod(row[7], nullptr) : 0; + e.mana_fac = row[8] ? strtod(row[8], nullptr) : 0; + e.end_fac = row[9] ? strtod(row[9], nullptr) : 0; all_entries.push_back(e); } @@ -340,16 +341,16 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { BaseData e{}; - e.level = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.hp = strtod(row[2], nullptr); - e.mana = strtod(row[3], nullptr); - e.end = strtod(row[4], nullptr); - e.unk1 = strtod(row[5], nullptr); - e.unk2 = strtod(row[6], nullptr); - e.hp_fac = strtod(row[7], nullptr); - e.mana_fac = strtod(row[8], nullptr); - e.end_fac = strtod(row[9], nullptr); + e.level = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.hp = row[2] ? strtod(row[2], nullptr) : 0; + e.mana = row[3] ? strtod(row[3], nullptr) : 0; + e.end = row[4] ? strtod(row[4], nullptr) : 0; + e.unk1 = row[5] ? strtod(row[5], nullptr) : 0; + e.unk2 = row[6] ? strtod(row[6], nullptr) : 0; + e.hp_fac = row[7] ? strtod(row[7], nullptr) : 0; + e.mana_fac = row[8] ? strtod(row[8], nullptr) : 0; + e.end_fac = row[9] ? strtod(row[9], nullptr) : 0; all_entries.push_back(e); } @@ -408,6 +409,80 @@ 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 BaseData &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.end)); + v.push_back(std::to_string(e.unk1)); + v.push_back(std::to_string(e.unk2)); + v.push_back(std::to_string(e.hp_fac)); + v.push_back(std::to_string(e.mana_fac)); + v.push_back(std::to_string(e.end_fac)); + + 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.level)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.end)); + v.push_back(std::to_string(e.unk1)); + v.push_back(std::to_string(e.unk2)); + v.push_back(std::to_string(e.hp_fac)); + v.push_back(std::to_string(e.mana_fac)); + v.push_back(std::to_string(e.end_fac)); + + 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_BASE_DATA_REPOSITORY_H diff --git a/common/repositories/base/base_blocked_spells_repository.h b/common/repositories/base/base_blocked_spells_repository.h index 3027049e3..e7df4f9ee 100644 --- a/common/repositories/base/base_blocked_spells_repository.h +++ b/common/repositories/base/base_blocked_spells_repository.h @@ -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_BLOCKED_SPELLS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseBlockedSpellsRepository { public: struct BlockedSpells { @@ -177,15 +176,15 @@ public: BlockedSpells e{}; e.id = static_cast(atoi(row[0])); - e.spellid = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.type = static_cast(atoi(row[2])); e.zoneid = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.x_diff = strtof(row[7], nullptr); - e.y_diff = strtof(row[8], nullptr); - e.z_diff = strtof(row[9], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.x_diff = row[7] ? strtof(row[7], nullptr) : 0; + e.y_diff = row[8] ? strtof(row[8], nullptr) : 0; + e.z_diff = row[9] ? strtof(row[9], nullptr) : 0; e.message = row[10] ? row[10] : ""; e.description = row[11] ? row[11] : ""; e.min_expansion = static_cast(atoi(row[12])); @@ -356,15 +355,15 @@ public: BlockedSpells e{}; e.id = static_cast(atoi(row[0])); - e.spellid = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.type = static_cast(atoi(row[2])); e.zoneid = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.x_diff = strtof(row[7], nullptr); - e.y_diff = strtof(row[8], nullptr); - e.z_diff = strtof(row[9], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.x_diff = row[7] ? strtof(row[7], nullptr) : 0; + e.y_diff = row[8] ? strtof(row[8], nullptr) : 0; + e.z_diff = row[9] ? strtof(row[9], nullptr) : 0; e.message = row[10] ? row[10] : ""; e.description = row[11] ? row[11] : ""; e.min_expansion = static_cast(atoi(row[12])); @@ -396,15 +395,15 @@ public: BlockedSpells e{}; e.id = static_cast(atoi(row[0])); - e.spellid = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.type = static_cast(atoi(row[2])); e.zoneid = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.x_diff = strtof(row[7], nullptr); - e.y_diff = strtof(row[8], nullptr); - e.z_diff = strtof(row[9], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.x_diff = row[7] ? strtof(row[7], nullptr) : 0; + e.y_diff = row[8] ? strtof(row[8], nullptr) : 0; + e.z_diff = row[9] ? strtof(row[9], nullptr) : 0; e.message = row[10] ? row[10] : ""; e.description = row[11] ? row[11] : ""; e.min_expansion = static_cast(atoi(row[12])); @@ -469,6 +468,92 @@ 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 BlockedSpells &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.x_diff)); + v.push_back(std::to_string(e.y_diff)); + v.push_back(std::to_string(e.z_diff)); + v.push_back("'" + Strings::Escape(e.message) + "'"); + v.push_back("'" + Strings::Escape(e.description) + "'"); + 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) + "'"); + + 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(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.x_diff)); + v.push_back(std::to_string(e.y_diff)); + v.push_back(std::to_string(e.z_diff)); + v.push_back("'" + Strings::Escape(e.message) + "'"); + v.push_back("'" + Strings::Escape(e.description) + "'"); + 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) + "'"); + + 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_BLOCKED_SPELLS_REPOSITORY_H diff --git a/common/repositories/base/base_books_repository.h b/common/repositories/base/base_books_repository.h index badbb2e7b..ff3a338f5 100644 --- a/common/repositories/base/base_books_repository.h +++ b/common/repositories/base/base_books_repository.h @@ -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_BOOKS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), books_id ) ); @@ -347,6 +348,68 @@ 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 Books &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.txtfile) + "'"); + v.push_back(std::to_string(e.language)); + + 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.name) + "'"); + v.push_back("'" + Strings::Escape(e.txtfile) + "'"); + v.push_back(std::to_string(e.language)); + + 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_BOOKS_REPOSITORY_H diff --git a/common/repositories/base/base_bug_reports_repository.h b/common/repositories/base/base_bug_reports_repository.h index 5e38742fa..4918f0621 100644 --- a/common/repositories/base/base_bug_reports_repository.h +++ b/common/repositories/base/base_bug_reports_repository.h @@ -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_BUG_REPORTS_REPOSITORY_H @@ -228,8 +228,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), bug_reports_id ) ); @@ -238,26 +239,26 @@ public: if (results.RowCount() == 1) { BugReports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.client_version_id = static_cast(strtoul(row[2], nullptr, 10)); + e.client_version_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.client_version_name = row[3] ? row[3] : ""; - e.account_id = static_cast(strtoul(row[4], nullptr, 10)); - e.character_id = static_cast(strtoul(row[5], nullptr, 10)); + e.account_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.character_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.character_name = row[6] ? row[6] : ""; e.reporter_spoof = static_cast(atoi(row[7])); - e.category_id = static_cast(strtoul(row[8], nullptr, 10)); + e.category_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.category_name = row[9] ? row[9] : ""; e.reporter_name = row[10] ? row[10] : ""; e.ui_path = row[11] ? row[11] : ""; - e.pos_x = strtof(row[12], nullptr); - e.pos_y = strtof(row[13], nullptr); - e.pos_z = strtof(row[14], nullptr); - e.heading = static_cast(strtoul(row[15], nullptr, 10)); - e.time_played = static_cast(strtoul(row[16], nullptr, 10)); - e.target_id = static_cast(strtoul(row[17], nullptr, 10)); + e.pos_x = row[12] ? strtof(row[12], nullptr) : 0; + e.pos_y = row[13] ? strtof(row[13], nullptr) : 0; + e.pos_z = row[14] ? strtof(row[14], nullptr) : 0; + e.heading = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.time_played = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.target_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.target_name = row[18] ? row[18] : ""; - e.optional_info_mask = static_cast(strtoul(row[19], nullptr, 10)); + e.optional_info_mask = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; e._can_duplicate = static_cast(atoi(row[20])); e._crash_bug = static_cast(atoi(row[21])); e._target_info = static_cast(atoi(row[22])); @@ -266,7 +267,7 @@ public: e.bug_report = row[25] ? row[25] : ""; e.system_info = row[26] ? row[26] : ""; e.report_datetime = strtoll(row[27] ? row[27] : "-1", nullptr, 10); - e.bug_status = static_cast(strtoul(row[28], nullptr, 10)); + e.bug_status = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; e.last_review = strtoll(row[29] ? row[29] : "-1", nullptr, 10); e.last_reviewer = row[30] ? row[30] : ""; e.reviewer_notes = row[31] ? row[31] : ""; @@ -481,26 +482,26 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { BugReports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.client_version_id = static_cast(strtoul(row[2], nullptr, 10)); + e.client_version_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.client_version_name = row[3] ? row[3] : ""; - e.account_id = static_cast(strtoul(row[4], nullptr, 10)); - e.character_id = static_cast(strtoul(row[5], nullptr, 10)); + e.account_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.character_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.character_name = row[6] ? row[6] : ""; e.reporter_spoof = static_cast(atoi(row[7])); - e.category_id = static_cast(strtoul(row[8], nullptr, 10)); + e.category_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.category_name = row[9] ? row[9] : ""; e.reporter_name = row[10] ? row[10] : ""; e.ui_path = row[11] ? row[11] : ""; - e.pos_x = strtof(row[12], nullptr); - e.pos_y = strtof(row[13], nullptr); - e.pos_z = strtof(row[14], nullptr); - e.heading = static_cast(strtoul(row[15], nullptr, 10)); - e.time_played = static_cast(strtoul(row[16], nullptr, 10)); - e.target_id = static_cast(strtoul(row[17], nullptr, 10)); + e.pos_x = row[12] ? strtof(row[12], nullptr) : 0; + e.pos_y = row[13] ? strtof(row[13], nullptr) : 0; + e.pos_z = row[14] ? strtof(row[14], nullptr) : 0; + e.heading = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.time_played = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.target_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.target_name = row[18] ? row[18] : ""; - e.optional_info_mask = static_cast(strtoul(row[19], nullptr, 10)); + e.optional_info_mask = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; e._can_duplicate = static_cast(atoi(row[20])); e._crash_bug = static_cast(atoi(row[21])); e._target_info = static_cast(atoi(row[22])); @@ -509,7 +510,7 @@ public: e.bug_report = row[25] ? row[25] : ""; e.system_info = row[26] ? row[26] : ""; e.report_datetime = strtoll(row[27] ? row[27] : "-1", nullptr, 10); - e.bug_status = static_cast(strtoul(row[28], nullptr, 10)); + e.bug_status = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; e.last_review = strtoll(row[29] ? row[29] : "-1", nullptr, 10); e.last_reviewer = row[30] ? row[30] : ""; e.reviewer_notes = row[31] ? row[31] : ""; @@ -537,26 +538,26 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { BugReports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.client_version_id = static_cast(strtoul(row[2], nullptr, 10)); + e.client_version_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.client_version_name = row[3] ? row[3] : ""; - e.account_id = static_cast(strtoul(row[4], nullptr, 10)); - e.character_id = static_cast(strtoul(row[5], nullptr, 10)); + e.account_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.character_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.character_name = row[6] ? row[6] : ""; e.reporter_spoof = static_cast(atoi(row[7])); - e.category_id = static_cast(strtoul(row[8], nullptr, 10)); + e.category_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.category_name = row[9] ? row[9] : ""; e.reporter_name = row[10] ? row[10] : ""; e.ui_path = row[11] ? row[11] : ""; - e.pos_x = strtof(row[12], nullptr); - e.pos_y = strtof(row[13], nullptr); - e.pos_z = strtof(row[14], nullptr); - e.heading = static_cast(strtoul(row[15], nullptr, 10)); - e.time_played = static_cast(strtoul(row[16], nullptr, 10)); - e.target_id = static_cast(strtoul(row[17], nullptr, 10)); + e.pos_x = row[12] ? strtof(row[12], nullptr) : 0; + e.pos_y = row[13] ? strtof(row[13], nullptr) : 0; + e.pos_z = row[14] ? strtof(row[14], nullptr) : 0; + e.heading = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.time_played = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.target_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.target_name = row[18] ? row[18] : ""; - e.optional_info_mask = static_cast(strtoul(row[19], nullptr, 10)); + e.optional_info_mask = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; e._can_duplicate = static_cast(atoi(row[20])); e._crash_bug = static_cast(atoi(row[21])); e._target_info = static_cast(atoi(row[22])); @@ -565,7 +566,7 @@ public: e.bug_report = row[25] ? row[25] : ""; e.system_info = row[26] ? row[26] : ""; e.report_datetime = strtoll(row[27] ? row[27] : "-1", nullptr, 10); - e.bug_status = static_cast(strtoul(row[28], nullptr, 10)); + e.bug_status = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; e.last_review = strtoll(row[29] ? row[29] : "-1", nullptr, 10); e.last_reviewer = row[30] ? row[30] : ""; e.reviewer_notes = row[31] ? row[31] : ""; @@ -627,6 +628,124 @@ 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 BugReports &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.client_version_id)); + v.push_back("'" + Strings::Escape(e.client_version_name) + "'"); + v.push_back(std::to_string(e.account_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back("'" + Strings::Escape(e.character_name) + "'"); + v.push_back(std::to_string(e.reporter_spoof)); + v.push_back(std::to_string(e.category_id)); + v.push_back("'" + Strings::Escape(e.category_name) + "'"); + v.push_back("'" + Strings::Escape(e.reporter_name) + "'"); + v.push_back("'" + Strings::Escape(e.ui_path) + "'"); + v.push_back(std::to_string(e.pos_x)); + v.push_back(std::to_string(e.pos_y)); + v.push_back(std::to_string(e.pos_z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.time_played)); + v.push_back(std::to_string(e.target_id)); + v.push_back("'" + Strings::Escape(e.target_name) + "'"); + v.push_back(std::to_string(e.optional_info_mask)); + v.push_back(std::to_string(e._can_duplicate)); + v.push_back(std::to_string(e._crash_bug)); + v.push_back(std::to_string(e._target_info)); + v.push_back(std::to_string(e._character_flags)); + v.push_back(std::to_string(e._unknown_value)); + v.push_back("'" + Strings::Escape(e.bug_report) + "'"); + v.push_back("'" + Strings::Escape(e.system_info) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.report_datetime > 0 ? std::to_string(e.report_datetime) : "null") + ")"); + v.push_back(std::to_string(e.bug_status)); + v.push_back("FROM_UNIXTIME(" + (e.last_review > 0 ? std::to_string(e.last_review) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.last_reviewer) + "'"); + v.push_back("'" + Strings::Escape(e.reviewer_notes) + "'"); + + 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.client_version_id)); + v.push_back("'" + Strings::Escape(e.client_version_name) + "'"); + v.push_back(std::to_string(e.account_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back("'" + Strings::Escape(e.character_name) + "'"); + v.push_back(std::to_string(e.reporter_spoof)); + v.push_back(std::to_string(e.category_id)); + v.push_back("'" + Strings::Escape(e.category_name) + "'"); + v.push_back("'" + Strings::Escape(e.reporter_name) + "'"); + v.push_back("'" + Strings::Escape(e.ui_path) + "'"); + v.push_back(std::to_string(e.pos_x)); + v.push_back(std::to_string(e.pos_y)); + v.push_back(std::to_string(e.pos_z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.time_played)); + v.push_back(std::to_string(e.target_id)); + v.push_back("'" + Strings::Escape(e.target_name) + "'"); + v.push_back(std::to_string(e.optional_info_mask)); + v.push_back(std::to_string(e._can_duplicate)); + v.push_back(std::to_string(e._crash_bug)); + v.push_back(std::to_string(e._target_info)); + v.push_back(std::to_string(e._character_flags)); + v.push_back(std::to_string(e._unknown_value)); + v.push_back("'" + Strings::Escape(e.bug_report) + "'"); + v.push_back("'" + Strings::Escape(e.system_info) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.report_datetime > 0 ? std::to_string(e.report_datetime) : "null") + ")"); + v.push_back(std::to_string(e.bug_status)); + v.push_back("FROM_UNIXTIME(" + (e.last_review > 0 ? std::to_string(e.last_review) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.last_reviewer) + "'"); + v.push_back("'" + Strings::Escape(e.reviewer_notes) + "'"); + + 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_BUG_REPORTS_REPOSITORY_H diff --git a/common/repositories/base/base_bugs_repository.h b/common/repositories/base/base_bugs_repository.h index 381fc4d01..343036435 100644 --- a/common/repositories/base/base_bugs_repository.h +++ b/common/repositories/base/base_bugs_repository.h @@ -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_BUGS_REPOSITORY_H @@ -152,8 +152,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), bugs_id ) ); @@ -162,19 +163,19 @@ public: if (results.RowCount() == 1) { Bugs e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; e.name = row[2] ? row[2] : ""; e.ui = row[3] ? row[3] : ""; - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; e.type = row[7] ? row[7] : ""; - e.flag = static_cast(strtoul(row[8], nullptr, 10)); + e.flag = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.target = row[9] ? row[9] : ""; e.bug = row[10] ? row[10] : ""; e.date = row[11] ? row[11] : ""; - e.status = static_cast(strtoul(row[12], nullptr, 10)); + e.status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; return e; } @@ -329,19 +330,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Bugs e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; e.name = row[2] ? row[2] : ""; e.ui = row[3] ? row[3] : ""; - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; e.type = row[7] ? row[7] : ""; - e.flag = static_cast(strtoul(row[8], nullptr, 10)); + e.flag = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.target = row[9] ? row[9] : ""; e.bug = row[10] ? row[10] : ""; e.date = row[11] ? row[11] : ""; - e.status = static_cast(strtoul(row[12], nullptr, 10)); + e.status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -366,19 +367,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Bugs e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; e.name = row[2] ? row[2] : ""; e.ui = row[3] ? row[3] : ""; - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; e.type = row[7] ? row[7] : ""; - e.flag = static_cast(strtoul(row[8], nullptr, 10)); + e.flag = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.target = row[9] ? row[9] : ""; e.bug = row[10] ? row[10] : ""; e.date = row[11] ? row[11] : ""; - e.status = static_cast(strtoul(row[12], nullptr, 10)); + e.status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -437,6 +438,86 @@ 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 Bugs &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.ui) + "'"); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back("'" + Strings::Escape(e.type) + "'"); + v.push_back(std::to_string(e.flag)); + v.push_back("'" + Strings::Escape(e.target) + "'"); + v.push_back("'" + Strings::Escape(e.bug) + "'"); + v.push_back("'" + Strings::Escape(e.date) + "'"); + v.push_back(std::to_string(e.status)); + + 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("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.ui) + "'"); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back("'" + Strings::Escape(e.type) + "'"); + v.push_back(std::to_string(e.flag)); + v.push_back("'" + Strings::Escape(e.target) + "'"); + v.push_back("'" + Strings::Escape(e.bug) + "'"); + v.push_back("'" + Strings::Escape(e.date) + "'"); + v.push_back(std::to_string(e.status)); + + 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_BUGS_REPOSITORY_H diff --git a/common/repositories/base/base_buyer_repository.h b/common/repositories/base/base_buyer_repository.h index 1e365481f..deb1b980d 100644 --- a/common/repositories/base/base_buyer_repository.h +++ b/common/repositories/base/base_buyer_repository.h @@ -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_BUYER_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), buyer_id ) ); @@ -368,6 +369,72 @@ 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 Buyer &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.buyslot)); + v.push_back(std::to_string(e.itemid)); + v.push_back("'" + Strings::Escape(e.itemname) + "'"); + v.push_back(std::to_string(e.quantity)); + v.push_back(std::to_string(e.price)); + + 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.charid)); + v.push_back(std::to_string(e.buyslot)); + v.push_back(std::to_string(e.itemid)); + v.push_back("'" + Strings::Escape(e.itemname) + "'"); + v.push_back(std::to_string(e.quantity)); + v.push_back(std::to_string(e.price)); + + 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_BUYER_REPOSITORY_H diff --git a/common/repositories/base/base_char_create_combinations_repository.h b/common/repositories/base/base_char_create_combinations_repository.h index 98eae33a9..82caa9ba4 100644 --- a/common/repositories/base/base_char_create_combinations_repository.h +++ b/common/repositories/base/base_char_create_combinations_repository.h @@ -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_CHAR_CREATE_COMBINATIONS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), char_create_combinations_id ) ); @@ -134,12 +135,12 @@ public: if (results.RowCount() == 1) { CharCreateCombinations e{}; - e.allocation_id = static_cast(strtoul(row[0], nullptr, 10)); - e.race = static_cast(strtoul(row[1], nullptr, 10)); - e.class_ = static_cast(strtoul(row[2], nullptr, 10)); - e.deity = static_cast(strtoul(row[3], nullptr, 10)); - e.start_zone = static_cast(strtoul(row[4], nullptr, 10)); - e.expansions_req = static_cast(strtoul(row[5], nullptr, 10)); + e.allocation_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.class_ = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.deity = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_zone = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.expansions_req = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; return e; } @@ -274,12 +275,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharCreateCombinations e{}; - e.allocation_id = static_cast(strtoul(row[0], nullptr, 10)); - e.race = static_cast(strtoul(row[1], nullptr, 10)); - e.class_ = static_cast(strtoul(row[2], nullptr, 10)); - e.deity = static_cast(strtoul(row[3], nullptr, 10)); - e.start_zone = static_cast(strtoul(row[4], nullptr, 10)); - e.expansions_req = static_cast(strtoul(row[5], nullptr, 10)); + e.allocation_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.class_ = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.deity = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_zone = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.expansions_req = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -304,12 +305,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharCreateCombinations e{}; - e.allocation_id = static_cast(strtoul(row[0], nullptr, 10)); - e.race = static_cast(strtoul(row[1], nullptr, 10)); - e.class_ = static_cast(strtoul(row[2], nullptr, 10)); - e.deity = static_cast(strtoul(row[3], nullptr, 10)); - e.start_zone = static_cast(strtoul(row[4], nullptr, 10)); - e.expansions_req = static_cast(strtoul(row[5], nullptr, 10)); + e.allocation_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.class_ = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.deity = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_zone = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.expansions_req = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -368,6 +369,72 @@ 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 CharCreateCombinations &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.allocation_id)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.start_zone)); + v.push_back(std::to_string(e.expansions_req)); + + 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.allocation_id)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.start_zone)); + v.push_back(std::to_string(e.expansions_req)); + + 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_CHAR_CREATE_COMBINATIONS_REPOSITORY_H diff --git a/common/repositories/base/base_char_create_point_allocations_repository.h b/common/repositories/base/base_char_create_point_allocations_repository.h index 4573a025b..f0e7fdeb0 100644 --- a/common/repositories/base/base_char_create_point_allocations_repository.h +++ b/common/repositories/base/base_char_create_point_allocations_repository.h @@ -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_CHAR_CREATE_POINT_ALLOCATIONS_REPOSITORY_H @@ -160,8 +160,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), char_create_point_allocations_id ) ); @@ -170,21 +171,21 @@ public: if (results.RowCount() == 1) { CharCreatePointAllocations e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.base_str = static_cast(strtoul(row[1], nullptr, 10)); - e.base_sta = static_cast(strtoul(row[2], nullptr, 10)); - e.base_dex = static_cast(strtoul(row[3], nullptr, 10)); - e.base_agi = static_cast(strtoul(row[4], nullptr, 10)); - e.base_int = static_cast(strtoul(row[5], nullptr, 10)); - e.base_wis = static_cast(strtoul(row[6], nullptr, 10)); - e.base_cha = static_cast(strtoul(row[7], nullptr, 10)); - e.alloc_str = static_cast(strtoul(row[8], nullptr, 10)); - e.alloc_sta = static_cast(strtoul(row[9], nullptr, 10)); - e.alloc_dex = static_cast(strtoul(row[10], nullptr, 10)); - e.alloc_agi = static_cast(strtoul(row[11], nullptr, 10)); - e.alloc_int = static_cast(strtoul(row[12], nullptr, 10)); - e.alloc_wis = static_cast(strtoul(row[13], nullptr, 10)); - e.alloc_cha = static_cast(strtoul(row[14], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.base_str = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.base_sta = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.base_dex = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.base_agi = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.base_int = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.base_wis = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.base_cha = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.alloc_str = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.alloc_sta = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.alloc_dex = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.alloc_agi = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.alloc_int = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.alloc_wis = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.alloc_cha = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; return e; } @@ -346,21 +347,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharCreatePointAllocations e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.base_str = static_cast(strtoul(row[1], nullptr, 10)); - e.base_sta = static_cast(strtoul(row[2], nullptr, 10)); - e.base_dex = static_cast(strtoul(row[3], nullptr, 10)); - e.base_agi = static_cast(strtoul(row[4], nullptr, 10)); - e.base_int = static_cast(strtoul(row[5], nullptr, 10)); - e.base_wis = static_cast(strtoul(row[6], nullptr, 10)); - e.base_cha = static_cast(strtoul(row[7], nullptr, 10)); - e.alloc_str = static_cast(strtoul(row[8], nullptr, 10)); - e.alloc_sta = static_cast(strtoul(row[9], nullptr, 10)); - e.alloc_dex = static_cast(strtoul(row[10], nullptr, 10)); - e.alloc_agi = static_cast(strtoul(row[11], nullptr, 10)); - e.alloc_int = static_cast(strtoul(row[12], nullptr, 10)); - e.alloc_wis = static_cast(strtoul(row[13], nullptr, 10)); - e.alloc_cha = static_cast(strtoul(row[14], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.base_str = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.base_sta = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.base_dex = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.base_agi = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.base_int = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.base_wis = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.base_cha = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.alloc_str = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.alloc_sta = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.alloc_dex = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.alloc_agi = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.alloc_int = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.alloc_wis = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.alloc_cha = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -385,21 +386,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharCreatePointAllocations e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.base_str = static_cast(strtoul(row[1], nullptr, 10)); - e.base_sta = static_cast(strtoul(row[2], nullptr, 10)); - e.base_dex = static_cast(strtoul(row[3], nullptr, 10)); - e.base_agi = static_cast(strtoul(row[4], nullptr, 10)); - e.base_int = static_cast(strtoul(row[5], nullptr, 10)); - e.base_wis = static_cast(strtoul(row[6], nullptr, 10)); - e.base_cha = static_cast(strtoul(row[7], nullptr, 10)); - e.alloc_str = static_cast(strtoul(row[8], nullptr, 10)); - e.alloc_sta = static_cast(strtoul(row[9], nullptr, 10)); - e.alloc_dex = static_cast(strtoul(row[10], nullptr, 10)); - e.alloc_agi = static_cast(strtoul(row[11], nullptr, 10)); - e.alloc_int = static_cast(strtoul(row[12], nullptr, 10)); - e.alloc_wis = static_cast(strtoul(row[13], nullptr, 10)); - e.alloc_cha = static_cast(strtoul(row[14], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.base_str = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.base_sta = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.base_dex = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.base_agi = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.base_int = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.base_wis = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.base_cha = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.alloc_str = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.alloc_sta = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.alloc_dex = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.alloc_agi = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.alloc_int = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.alloc_wis = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.alloc_cha = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -458,6 +459,90 @@ 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 CharCreatePointAllocations &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.base_str)); + v.push_back(std::to_string(e.base_sta)); + v.push_back(std::to_string(e.base_dex)); + v.push_back(std::to_string(e.base_agi)); + v.push_back(std::to_string(e.base_int)); + v.push_back(std::to_string(e.base_wis)); + v.push_back(std::to_string(e.base_cha)); + v.push_back(std::to_string(e.alloc_str)); + v.push_back(std::to_string(e.alloc_sta)); + v.push_back(std::to_string(e.alloc_dex)); + v.push_back(std::to_string(e.alloc_agi)); + v.push_back(std::to_string(e.alloc_int)); + v.push_back(std::to_string(e.alloc_wis)); + v.push_back(std::to_string(e.alloc_cha)); + + 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(std::to_string(e.base_str)); + v.push_back(std::to_string(e.base_sta)); + v.push_back(std::to_string(e.base_dex)); + v.push_back(std::to_string(e.base_agi)); + v.push_back(std::to_string(e.base_int)); + v.push_back(std::to_string(e.base_wis)); + v.push_back(std::to_string(e.base_cha)); + v.push_back(std::to_string(e.alloc_str)); + v.push_back(std::to_string(e.alloc_sta)); + v.push_back(std::to_string(e.alloc_dex)); + v.push_back(std::to_string(e.alloc_agi)); + v.push_back(std::to_string(e.alloc_int)); + v.push_back(std::to_string(e.alloc_wis)); + v.push_back(std::to_string(e.alloc_cha)); + + 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_CHAR_CREATE_POINT_ALLOCATIONS_REPOSITORY_H diff --git a/common/repositories/base/base_char_recipe_list_repository.h b/common/repositories/base/base_char_recipe_list_repository.h index 5ae76ef4f..e3413243f 100644 --- a/common/repositories/base/base_char_recipe_list_repository.h +++ b/common/repositories/base/base_char_recipe_list_repository.h @@ -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_CHAR_RECIPE_LIST_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), char_recipe_list_id ) ); @@ -338,6 +339,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 CharRecipeList &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.recipe_id)); + v.push_back(std::to_string(e.madecount)); + + 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.char_id)); + v.push_back(std::to_string(e.recipe_id)); + v.push_back(std::to_string(e.madecount)); + + 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_CHAR_RECIPE_LIST_REPOSITORY_H diff --git a/common/repositories/base/base_character_activities_repository.h b/common/repositories/base/base_character_activities_repository.h index b365bd81a..fd20c3b43 100644 --- a/common/repositories/base/base_character_activities_repository.h +++ b/common/repositories/base/base_character_activities_repository.h @@ -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_ACTIVITIES_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_activities_id ) ); @@ -130,10 +131,10 @@ public: if (results.RowCount() == 1) { CharacterActivities e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.activityid = static_cast(strtoul(row[2], nullptr, 10)); - e.donecount = static_cast(strtoul(row[3], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.activityid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.donecount = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.completed = static_cast(atoi(row[4])); return e; @@ -266,10 +267,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterActivities e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.activityid = static_cast(strtoul(row[2], nullptr, 10)); - e.donecount = static_cast(strtoul(row[3], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.activityid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.donecount = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.completed = static_cast(atoi(row[4])); all_entries.push_back(e); @@ -295,10 +296,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterActivities e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.activityid = static_cast(strtoul(row[2], nullptr, 10)); - e.donecount = static_cast(strtoul(row[3], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.activityid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.donecount = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.completed = static_cast(atoi(row[4])); all_entries.push_back(e); @@ -358,6 +359,70 @@ 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 CharacterActivities &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.activityid)); + v.push_back(std::to_string(e.donecount)); + v.push_back(std::to_string(e.completed)); + + 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.charid)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.activityid)); + v.push_back(std::to_string(e.donecount)); + v.push_back(std::to_string(e.completed)); + + 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_CHARACTER_ACTIVITIES_REPOSITORY_H diff --git a/common/repositories/base/base_character_alt_currency_repository.h b/common/repositories/base/base_character_alt_currency_repository.h index 7e9a64f71..f4cd4d76b 100644 --- a/common/repositories/base/base_character_alt_currency_repository.h +++ b/common/repositories/base/base_character_alt_currency_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterAltCurrencyRepository { public: struct CharacterAltCurrency { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterAltCurrency e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.currency_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.currency_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -252,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterAltCurrency e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.currency_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.currency_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -279,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterAltCurrency e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.currency_id = static_cast(strtoul(row[1], nullptr, 10)); - e.amount = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.currency_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.amount = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_alternate_abilities_repository.h b/common/repositories/base/base_character_alternate_abilities_repository.h index 4fcf935b9..951b0aec8 100644 --- a/common/repositories/base/base_character_alternate_abilities_repository.h +++ b/common/repositories/base/base_character_alternate_abilities_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterAlternateAbilitiesRepository { public: struct CharacterAlternateAbilities { @@ -128,10 +127,10 @@ public: if (results.RowCount() == 1) { CharacterAlternateAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.aa_id = static_cast(strtoul(row[1], nullptr, 10)); - e.aa_value = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.aa_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.aa_value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -260,10 +259,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterAlternateAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.aa_id = static_cast(strtoul(row[1], nullptr, 10)); - e.aa_value = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.aa_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.aa_value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -288,10 +287,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterAlternateAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.aa_id = static_cast(strtoul(row[1], nullptr, 10)); - e.aa_value = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.aa_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.aa_value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_auras_repository.h b/common/repositories/base/base_character_auras_repository.h index ec4b83d6d..8eca4d659 100644 --- a/common/repositories/base/base_character_auras_repository.h +++ b/common/repositories/base/base_character_auras_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterAurasRepository { public: struct CharacterAuras { diff --git a/common/repositories/base/base_character_bandolier_repository.h b/common/repositories/base/base_character_bandolier_repository.h index 4cc78840a..df41efaa8 100644 --- a/common/repositories/base/base_character_bandolier_repository.h +++ b/common/repositories/base/base_character_bandolier_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterBandolierRepository { public: struct CharacterBandolier { @@ -136,11 +135,11 @@ public: if (results.RowCount() == 1) { CharacterBandolier e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.bandolier_id = static_cast(strtoul(row[1], nullptr, 10)); - e.bandolier_slot = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); - e.icon = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.bandolier_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bandolier_slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.icon = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.bandolier_name = row[5] ? row[5] : ""; return e; @@ -276,11 +275,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBandolier e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.bandolier_id = static_cast(strtoul(row[1], nullptr, 10)); - e.bandolier_slot = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); - e.icon = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.bandolier_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bandolier_slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.icon = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.bandolier_name = row[5] ? row[5] : ""; all_entries.push_back(e); @@ -306,11 +305,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBandolier e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.bandolier_id = static_cast(strtoul(row[1], nullptr, 10)); - e.bandolier_slot = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); - e.icon = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.bandolier_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bandolier_slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.icon = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.bandolier_name = row[5] ? row[5] : ""; all_entries.push_back(e); diff --git a/common/repositories/base/base_character_bind_repository.h b/common/repositories/base/base_character_bind_repository.h index 0de508e88..663c5c149 100644 --- a/common/repositories/base/base_character_bind_repository.h +++ b/common/repositories/base/base_character_bind_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterBindRepository { public: struct CharacterBind { @@ -144,14 +143,14 @@ public: if (results.RowCount() == 1) { CharacterBind e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.slot = static_cast(atoi(row[1])); - e.zone_id = static_cast(strtoul(row[2], nullptr, 10)); - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.zone_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; return e; } @@ -291,14 +290,14 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBind e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.slot = static_cast(atoi(row[1])); - e.zone_id = static_cast(strtoul(row[2], nullptr, 10)); - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.zone_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; all_entries.push_back(e); } @@ -323,14 +322,14 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBind e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.slot = static_cast(atoi(row[1])); - e.zone_id = static_cast(strtoul(row[2], nullptr, 10)); - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.zone_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.x = row[4] ? strtof(row[4], nullptr) : 0; + e.y = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_buffs_repository.h b/common/repositories/base/base_character_buffs_repository.h index 4b3124c29..c405b6715 100644 --- a/common/repositories/base/base_character_buffs_repository.h +++ b/common/repositories/base/base_character_buffs_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterBuffsRepository { public: struct CharacterBuffs { @@ -180,17 +179,17 @@ public: if (results.RowCount() == 1) { CharacterBuffs e{}; - e.character_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.caster_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.caster_name = row[4] ? row[4] : ""; e.ticsremaining = static_cast(atoi(row[5])); - e.counters = static_cast(strtoul(row[6], nullptr, 10)); - e.numhits = static_cast(strtoul(row[7], nullptr, 10)); - e.melee_rune = static_cast(strtoul(row[8], nullptr, 10)); - e.magic_rune = static_cast(strtoul(row[9], nullptr, 10)); - e.persistent = static_cast(strtoul(row[10], nullptr, 10)); + e.counters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.numhits = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.melee_rune = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.magic_rune = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.persistent = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[11])); e.caston_x = static_cast(atoi(row[12])); e.caston_y = static_cast(atoi(row[13])); @@ -364,17 +363,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBuffs e{}; - e.character_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.caster_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.caster_name = row[4] ? row[4] : ""; e.ticsremaining = static_cast(atoi(row[5])); - e.counters = static_cast(strtoul(row[6], nullptr, 10)); - e.numhits = static_cast(strtoul(row[7], nullptr, 10)); - e.melee_rune = static_cast(strtoul(row[8], nullptr, 10)); - e.magic_rune = static_cast(strtoul(row[9], nullptr, 10)); - e.persistent = static_cast(strtoul(row[10], nullptr, 10)); + e.counters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.numhits = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.melee_rune = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.magic_rune = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.persistent = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[11])); e.caston_x = static_cast(atoi(row[12])); e.caston_y = static_cast(atoi(row[13])); @@ -405,17 +404,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterBuffs e{}; - e.character_id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.caster_level = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.caster_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.caster_name = row[4] ? row[4] : ""; e.ticsremaining = static_cast(atoi(row[5])); - e.counters = static_cast(strtoul(row[6], nullptr, 10)); - e.numhits = static_cast(strtoul(row[7], nullptr, 10)); - e.melee_rune = static_cast(strtoul(row[8], nullptr, 10)); - e.magic_rune = static_cast(strtoul(row[9], nullptr, 10)); - e.persistent = static_cast(strtoul(row[10], nullptr, 10)); + e.counters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.numhits = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.melee_rune = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.magic_rune = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.persistent = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[11])); e.caston_x = static_cast(atoi(row[12])); e.caston_y = static_cast(atoi(row[13])); diff --git a/common/repositories/base/base_character_corpse_items_repository.h b/common/repositories/base/base_character_corpse_items_repository.h index fbee91a78..13bdc483d 100644 --- a/common/repositories/base/base_character_corpse_items_repository.h +++ b/common/repositories/base/base_character_corpse_items_repository.h @@ -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_CORPSE_ITEMS_REPOSITORY_H @@ -19,17 +19,21 @@ class BaseCharacterCorpseItemsRepository { public: struct CharacterCorpseItems { - uint32_t corpse_id; - uint32_t equip_slot; - uint32_t item_id; - uint32_t charges; - uint32_t aug_1; - uint32_t aug_2; - uint32_t aug_3; - uint32_t aug_4; - uint32_t aug_5; - int32_t aug_6; - int16_t attuned; + uint32_t corpse_id; + uint32_t equip_slot; + uint32_t item_id; + uint32_t charges; + uint32_t aug_1; + uint32_t aug_2; + uint32_t aug_3; + uint32_t aug_4; + uint32_t aug_5; + int32_t aug_6; + int16_t attuned; + std::string custom_data; + uint32_t ornamenticon; + uint32_t ornamentidfile; + uint32_t ornament_hero_model; }; static std::string PrimaryKey() @@ -51,6 +55,10 @@ public: "aug_5", "aug_6", "attuned", + "custom_data", + "ornamenticon", + "ornamentidfile", + "ornament_hero_model", }; } @@ -68,6 +76,10 @@ public: "aug_5", "aug_6", "attuned", + "custom_data", + "ornamenticon", + "ornamentidfile", + "ornament_hero_model", }; } @@ -108,17 +120,21 @@ public: { CharacterCorpseItems e{}; - e.corpse_id = 0; - e.equip_slot = 0; - e.item_id = 0; - e.charges = 0; - e.aug_1 = 0; - e.aug_2 = 0; - e.aug_3 = 0; - e.aug_4 = 0; - e.aug_5 = 0; - e.aug_6 = 0; - e.attuned = 0; + e.corpse_id = 0; + e.equip_slot = 0; + e.item_id = 0; + e.charges = 0; + e.aug_1 = 0; + e.aug_2 = 0; + e.aug_3 = 0; + e.aug_4 = 0; + e.aug_5 = 0; + e.aug_6 = 0; + e.attuned = 0; + e.custom_data = ""; + e.ornamenticon = 0; + e.ornamentidfile = 0; + e.ornament_hero_model = 0; return e; } @@ -144,8 +160,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_corpse_items_id ) ); @@ -154,17 +171,21 @@ public: if (results.RowCount() == 1) { CharacterCorpseItems e{}; - e.corpse_id = static_cast(strtoul(row[0], nullptr, 10)); - e.equip_slot = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.aug_1 = static_cast(strtoul(row[4], nullptr, 10)); - e.aug_2 = static_cast(strtoul(row[5], nullptr, 10)); - e.aug_3 = static_cast(strtoul(row[6], nullptr, 10)); - e.aug_4 = static_cast(strtoul(row[7], nullptr, 10)); - e.aug_5 = static_cast(strtoul(row[8], nullptr, 10)); - e.aug_6 = static_cast(atoi(row[9])); - e.attuned = static_cast(atoi(row[10])); + e.corpse_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.equip_slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.aug_1 = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.aug_2 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aug_3 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.aug_4 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.aug_5 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.aug_6 = static_cast(atoi(row[9])); + e.attuned = static_cast(atoi(row[10])); + e.custom_data = row[11] ? row[11] : ""; + e.ornamenticon = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.ornamentidfile = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornament_hero_model = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; return e; } @@ -209,6 +230,10 @@ public: v.push_back(columns[8] + " = " + std::to_string(e.aug_5)); v.push_back(columns[9] + " = " + std::to_string(e.aug_6)); v.push_back(columns[10] + " = " + std::to_string(e.attuned)); + v.push_back(columns[11] + " = '" + Strings::Escape(e.custom_data) + "'"); + v.push_back(columns[12] + " = " + std::to_string(e.ornamenticon)); + v.push_back(columns[13] + " = " + std::to_string(e.ornamentidfile)); + v.push_back(columns[14] + " = " + std::to_string(e.ornament_hero_model)); auto results = db.QueryDatabase( fmt::format( @@ -241,6 +266,10 @@ public: v.push_back(std::to_string(e.aug_5)); v.push_back(std::to_string(e.aug_6)); v.push_back(std::to_string(e.attuned)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); auto results = db.QueryDatabase( fmt::format( @@ -281,6 +310,10 @@ public: v.push_back(std::to_string(e.aug_5)); v.push_back(std::to_string(e.aug_6)); v.push_back(std::to_string(e.attuned)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } @@ -314,17 +347,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCorpseItems e{}; - e.corpse_id = static_cast(strtoul(row[0], nullptr, 10)); - e.equip_slot = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.aug_1 = static_cast(strtoul(row[4], nullptr, 10)); - e.aug_2 = static_cast(strtoul(row[5], nullptr, 10)); - e.aug_3 = static_cast(strtoul(row[6], nullptr, 10)); - e.aug_4 = static_cast(strtoul(row[7], nullptr, 10)); - e.aug_5 = static_cast(strtoul(row[8], nullptr, 10)); - e.aug_6 = static_cast(atoi(row[9])); - e.attuned = static_cast(atoi(row[10])); + e.corpse_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.equip_slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.aug_1 = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.aug_2 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aug_3 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.aug_4 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.aug_5 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.aug_6 = static_cast(atoi(row[9])); + e.attuned = static_cast(atoi(row[10])); + e.custom_data = row[11] ? row[11] : ""; + e.ornamenticon = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.ornamentidfile = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornament_hero_model = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -349,17 +386,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCorpseItems e{}; - e.corpse_id = static_cast(strtoul(row[0], nullptr, 10)); - e.equip_slot = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.aug_1 = static_cast(strtoul(row[4], nullptr, 10)); - e.aug_2 = static_cast(strtoul(row[5], nullptr, 10)); - e.aug_3 = static_cast(strtoul(row[6], nullptr, 10)); - e.aug_4 = static_cast(strtoul(row[7], nullptr, 10)); - e.aug_5 = static_cast(strtoul(row[8], nullptr, 10)); - e.aug_6 = static_cast(atoi(row[9])); - e.attuned = static_cast(atoi(row[10])); + e.corpse_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.equip_slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.aug_1 = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.aug_2 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aug_3 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.aug_4 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.aug_5 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.aug_6 = static_cast(atoi(row[9])); + e.attuned = static_cast(atoi(row[10])); + e.custom_data = row[11] ? row[11] : ""; + e.ornamenticon = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.ornamentidfile = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornament_hero_model = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -418,6 +459,90 @@ 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 CharacterCorpseItems &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.corpse_id)); + v.push_back(std::to_string(e.equip_slot)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.aug_1)); + v.push_back(std::to_string(e.aug_2)); + v.push_back(std::to_string(e.aug_3)); + v.push_back(std::to_string(e.aug_4)); + v.push_back(std::to_string(e.aug_5)); + v.push_back(std::to_string(e.aug_6)); + v.push_back(std::to_string(e.attuned)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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.corpse_id)); + v.push_back(std::to_string(e.equip_slot)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.aug_1)); + v.push_back(std::to_string(e.aug_2)); + v.push_back(std::to_string(e.aug_3)); + v.push_back(std::to_string(e.aug_4)); + v.push_back(std::to_string(e.aug_5)); + v.push_back(std::to_string(e.aug_6)); + v.push_back(std::to_string(e.attuned)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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_CHARACTER_CORPSE_ITEMS_REPOSITORY_H diff --git a/common/repositories/base/base_character_corpses_repository.h b/common/repositories/base/base_character_corpses_repository.h index 1e4de5d8d..ec8c7e53d 100644 --- a/common/repositories/base/base_character_corpses_repository.h +++ b/common/repositories/base/base_character_corpses_repository.h @@ -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_CORPSES_REPOSITORY_H @@ -288,8 +288,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_corpses_id ) ); @@ -298,53 +299,53 @@ public: if (results.RowCount() == 1) { CharacterCorpses e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.zone_id = static_cast(atoi(row[3])); - e.instance_id = static_cast(strtoul(row[4], nullptr, 10)); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.instance_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.time_of_death = strtoll(row[9] ? row[9] : "-1", nullptr, 10); - e.guild_consent_id = static_cast(strtoul(row[10], nullptr, 10)); - e.is_rezzed = static_cast(strtoul(row[11], nullptr, 10)); + e.guild_consent_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.is_rezzed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.is_buried = static_cast(atoi(row[12])); e.was_at_graveyard = static_cast(atoi(row[13])); e.is_locked = static_cast(atoi(row[14])); - e.exp = static_cast(strtoul(row[15], nullptr, 10)); - e.size = static_cast(strtoul(row[16], nullptr, 10)); - e.level = static_cast(strtoul(row[17], nullptr, 10)); - e.race = static_cast(strtoul(row[18], nullptr, 10)); - e.gender = static_cast(strtoul(row[19], nullptr, 10)); - e.class_ = static_cast(strtoul(row[20], nullptr, 10)); - e.deity = static_cast(strtoul(row[21], nullptr, 10)); - e.texture = static_cast(strtoul(row[22], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[23], nullptr, 10)); - e.copper = static_cast(strtoul(row[24], nullptr, 10)); - e.silver = static_cast(strtoul(row[25], nullptr, 10)); - e.gold = static_cast(strtoul(row[26], nullptr, 10)); - e.platinum = static_cast(strtoul(row[27], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[28], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[29], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[30], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[31], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[32], nullptr, 10)); - e.face = static_cast(strtoul(row[33], nullptr, 10)); - e.beard = static_cast(strtoul(row[34], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[35], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[36], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[37], nullptr, 10)); - e.wc_1 = static_cast(strtoul(row[38], nullptr, 10)); - e.wc_2 = static_cast(strtoul(row[39], nullptr, 10)); - e.wc_3 = static_cast(strtoul(row[40], nullptr, 10)); - e.wc_4 = static_cast(strtoul(row[41], nullptr, 10)); - e.wc_5 = static_cast(strtoul(row[42], nullptr, 10)); - e.wc_6 = static_cast(strtoul(row[43], nullptr, 10)); - e.wc_7 = static_cast(strtoul(row[44], nullptr, 10)); - e.wc_8 = static_cast(strtoul(row[45], nullptr, 10)); - e.wc_9 = static_cast(strtoul(row[46], nullptr, 10)); + e.exp = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.size = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.level = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.race = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.gender = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.class_ = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.deity = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.texture = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.helm_texture = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.copper = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.silver = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.gold = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.platinum = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.hair_color = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.beard_color = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.eye_color_1 = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.eye_color_2 = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.hair_style = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.face = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.beard = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.drakkin_heritage = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.drakkin_tattoo = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.drakkin_details = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.wc_1 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.wc_2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.wc_3 = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.wc_4 = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.wc_5 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.wc_6 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.wc_7 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.wc_8 = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.wc_9 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; return e; } @@ -601,53 +602,53 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCorpses e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.zone_id = static_cast(atoi(row[3])); - e.instance_id = static_cast(strtoul(row[4], nullptr, 10)); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.instance_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.time_of_death = strtoll(row[9] ? row[9] : "-1", nullptr, 10); - e.guild_consent_id = static_cast(strtoul(row[10], nullptr, 10)); - e.is_rezzed = static_cast(strtoul(row[11], nullptr, 10)); + e.guild_consent_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.is_rezzed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.is_buried = static_cast(atoi(row[12])); e.was_at_graveyard = static_cast(atoi(row[13])); e.is_locked = static_cast(atoi(row[14])); - e.exp = static_cast(strtoul(row[15], nullptr, 10)); - e.size = static_cast(strtoul(row[16], nullptr, 10)); - e.level = static_cast(strtoul(row[17], nullptr, 10)); - e.race = static_cast(strtoul(row[18], nullptr, 10)); - e.gender = static_cast(strtoul(row[19], nullptr, 10)); - e.class_ = static_cast(strtoul(row[20], nullptr, 10)); - e.deity = static_cast(strtoul(row[21], nullptr, 10)); - e.texture = static_cast(strtoul(row[22], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[23], nullptr, 10)); - e.copper = static_cast(strtoul(row[24], nullptr, 10)); - e.silver = static_cast(strtoul(row[25], nullptr, 10)); - e.gold = static_cast(strtoul(row[26], nullptr, 10)); - e.platinum = static_cast(strtoul(row[27], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[28], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[29], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[30], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[31], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[32], nullptr, 10)); - e.face = static_cast(strtoul(row[33], nullptr, 10)); - e.beard = static_cast(strtoul(row[34], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[35], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[36], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[37], nullptr, 10)); - e.wc_1 = static_cast(strtoul(row[38], nullptr, 10)); - e.wc_2 = static_cast(strtoul(row[39], nullptr, 10)); - e.wc_3 = static_cast(strtoul(row[40], nullptr, 10)); - e.wc_4 = static_cast(strtoul(row[41], nullptr, 10)); - e.wc_5 = static_cast(strtoul(row[42], nullptr, 10)); - e.wc_6 = static_cast(strtoul(row[43], nullptr, 10)); - e.wc_7 = static_cast(strtoul(row[44], nullptr, 10)); - e.wc_8 = static_cast(strtoul(row[45], nullptr, 10)); - e.wc_9 = static_cast(strtoul(row[46], nullptr, 10)); + e.exp = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.size = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.level = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.race = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.gender = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.class_ = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.deity = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.texture = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.helm_texture = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.copper = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.silver = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.gold = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.platinum = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.hair_color = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.beard_color = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.eye_color_1 = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.eye_color_2 = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.hair_style = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.face = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.beard = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.drakkin_heritage = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.drakkin_tattoo = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.drakkin_details = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.wc_1 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.wc_2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.wc_3 = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.wc_4 = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.wc_5 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.wc_6 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.wc_7 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.wc_8 = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.wc_9 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -672,53 +673,53 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCorpses e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.zone_id = static_cast(atoi(row[3])); - e.instance_id = static_cast(strtoul(row[4], nullptr, 10)); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.instance_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.time_of_death = strtoll(row[9] ? row[9] : "-1", nullptr, 10); - e.guild_consent_id = static_cast(strtoul(row[10], nullptr, 10)); - e.is_rezzed = static_cast(strtoul(row[11], nullptr, 10)); + e.guild_consent_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.is_rezzed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.is_buried = static_cast(atoi(row[12])); e.was_at_graveyard = static_cast(atoi(row[13])); e.is_locked = static_cast(atoi(row[14])); - e.exp = static_cast(strtoul(row[15], nullptr, 10)); - e.size = static_cast(strtoul(row[16], nullptr, 10)); - e.level = static_cast(strtoul(row[17], nullptr, 10)); - e.race = static_cast(strtoul(row[18], nullptr, 10)); - e.gender = static_cast(strtoul(row[19], nullptr, 10)); - e.class_ = static_cast(strtoul(row[20], nullptr, 10)); - e.deity = static_cast(strtoul(row[21], nullptr, 10)); - e.texture = static_cast(strtoul(row[22], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[23], nullptr, 10)); - e.copper = static_cast(strtoul(row[24], nullptr, 10)); - e.silver = static_cast(strtoul(row[25], nullptr, 10)); - e.gold = static_cast(strtoul(row[26], nullptr, 10)); - e.platinum = static_cast(strtoul(row[27], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[28], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[29], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[30], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[31], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[32], nullptr, 10)); - e.face = static_cast(strtoul(row[33], nullptr, 10)); - e.beard = static_cast(strtoul(row[34], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[35], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[36], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[37], nullptr, 10)); - e.wc_1 = static_cast(strtoul(row[38], nullptr, 10)); - e.wc_2 = static_cast(strtoul(row[39], nullptr, 10)); - e.wc_3 = static_cast(strtoul(row[40], nullptr, 10)); - e.wc_4 = static_cast(strtoul(row[41], nullptr, 10)); - e.wc_5 = static_cast(strtoul(row[42], nullptr, 10)); - e.wc_6 = static_cast(strtoul(row[43], nullptr, 10)); - e.wc_7 = static_cast(strtoul(row[44], nullptr, 10)); - e.wc_8 = static_cast(strtoul(row[45], nullptr, 10)); - e.wc_9 = static_cast(strtoul(row[46], nullptr, 10)); + e.exp = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.size = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.level = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.race = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.gender = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.class_ = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.deity = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.texture = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.helm_texture = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.copper = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.silver = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.gold = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.platinum = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.hair_color = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.beard_color = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.eye_color_1 = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.eye_color_2 = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.hair_style = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.face = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.beard = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.drakkin_heritage = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.drakkin_tattoo = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.drakkin_details = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.wc_1 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.wc_2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.wc_3 = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.wc_4 = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.wc_5 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.wc_6 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.wc_7 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.wc_8 = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.wc_9 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -777,6 +778,154 @@ 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 CharacterCorpses &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.charid)); + v.push_back("'" + Strings::Escape(e.charname) + "'"); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_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)); + v.push_back(std::to_string(e.heading)); + v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")"); + v.push_back(std::to_string(e.guild_consent_id)); + v.push_back(std::to_string(e.is_rezzed)); + v.push_back(std::to_string(e.is_buried)); + v.push_back(std::to_string(e.was_at_graveyard)); + v.push_back(std::to_string(e.is_locked)); + v.push_back(std::to_string(e.exp)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helm_texture)); + v.push_back(std::to_string(e.copper)); + v.push_back(std::to_string(e.silver)); + v.push_back(std::to_string(e.gold)); + v.push_back(std::to_string(e.platinum)); + v.push_back(std::to_string(e.hair_color)); + v.push_back(std::to_string(e.beard_color)); + v.push_back(std::to_string(e.eye_color_1)); + v.push_back(std::to_string(e.eye_color_2)); + v.push_back(std::to_string(e.hair_style)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.beard)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.wc_1)); + v.push_back(std::to_string(e.wc_2)); + v.push_back(std::to_string(e.wc_3)); + v.push_back(std::to_string(e.wc_4)); + v.push_back(std::to_string(e.wc_5)); + v.push_back(std::to_string(e.wc_6)); + v.push_back(std::to_string(e.wc_7)); + v.push_back(std::to_string(e.wc_8)); + v.push_back(std::to_string(e.wc_9)); + + 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(std::to_string(e.charid)); + v.push_back("'" + Strings::Escape(e.charname) + "'"); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_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)); + v.push_back(std::to_string(e.heading)); + v.push_back("FROM_UNIXTIME(" + (e.time_of_death > 0 ? std::to_string(e.time_of_death) : "null") + ")"); + v.push_back(std::to_string(e.guild_consent_id)); + v.push_back(std::to_string(e.is_rezzed)); + v.push_back(std::to_string(e.is_buried)); + v.push_back(std::to_string(e.was_at_graveyard)); + v.push_back(std::to_string(e.is_locked)); + v.push_back(std::to_string(e.exp)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helm_texture)); + v.push_back(std::to_string(e.copper)); + v.push_back(std::to_string(e.silver)); + v.push_back(std::to_string(e.gold)); + v.push_back(std::to_string(e.platinum)); + v.push_back(std::to_string(e.hair_color)); + v.push_back(std::to_string(e.beard_color)); + v.push_back(std::to_string(e.eye_color_1)); + v.push_back(std::to_string(e.eye_color_2)); + v.push_back(std::to_string(e.hair_style)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.beard)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.wc_1)); + v.push_back(std::to_string(e.wc_2)); + v.push_back(std::to_string(e.wc_3)); + v.push_back(std::to_string(e.wc_4)); + v.push_back(std::to_string(e.wc_5)); + v.push_back(std::to_string(e.wc_6)); + v.push_back(std::to_string(e.wc_7)); + v.push_back(std::to_string(e.wc_8)); + v.push_back(std::to_string(e.wc_9)); + + 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_CHARACTER_CORPSES_REPOSITORY_H diff --git a/common/repositories/base/base_character_currency_repository.h b/common/repositories/base/base_character_currency_repository.h index 63744d506..c0ef4ed1f 100644 --- a/common/repositories/base/base_character_currency_repository.h +++ b/common/repositories/base/base_character_currency_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterCurrencyRepository { public: struct CharacterCurrency { @@ -180,23 +179,23 @@ public: if (results.RowCount() == 1) { CharacterCurrency e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.platinum = static_cast(strtoul(row[1], nullptr, 10)); - e.gold = static_cast(strtoul(row[2], nullptr, 10)); - e.silver = static_cast(strtoul(row[3], nullptr, 10)); - e.copper = static_cast(strtoul(row[4], nullptr, 10)); - e.platinum_bank = static_cast(strtoul(row[5], nullptr, 10)); - e.gold_bank = static_cast(strtoul(row[6], nullptr, 10)); - e.silver_bank = static_cast(strtoul(row[7], nullptr, 10)); - e.copper_bank = static_cast(strtoul(row[8], nullptr, 10)); - e.platinum_cursor = static_cast(strtoul(row[9], nullptr, 10)); - e.gold_cursor = static_cast(strtoul(row[10], nullptr, 10)); - e.silver_cursor = static_cast(strtoul(row[11], nullptr, 10)); - e.copper_cursor = static_cast(strtoul(row[12], nullptr, 10)); - e.radiant_crystals = static_cast(strtoul(row[13], nullptr, 10)); - e.career_radiant_crystals = static_cast(strtoul(row[14], nullptr, 10)); - e.ebon_crystals = static_cast(strtoul(row[15], nullptr, 10)); - e.career_ebon_crystals = static_cast(strtoul(row[16], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.platinum = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.gold = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.silver = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.copper = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.platinum_bank = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.gold_bank = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.silver_bank = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.copper_bank = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.platinum_cursor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.gold_cursor = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.silver_cursor = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.copper_cursor = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.radiant_crystals = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.career_radiant_crystals = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ebon_crystals = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.career_ebon_crystals = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; return e; } @@ -364,23 +363,23 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCurrency e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.platinum = static_cast(strtoul(row[1], nullptr, 10)); - e.gold = static_cast(strtoul(row[2], nullptr, 10)); - e.silver = static_cast(strtoul(row[3], nullptr, 10)); - e.copper = static_cast(strtoul(row[4], nullptr, 10)); - e.platinum_bank = static_cast(strtoul(row[5], nullptr, 10)); - e.gold_bank = static_cast(strtoul(row[6], nullptr, 10)); - e.silver_bank = static_cast(strtoul(row[7], nullptr, 10)); - e.copper_bank = static_cast(strtoul(row[8], nullptr, 10)); - e.platinum_cursor = static_cast(strtoul(row[9], nullptr, 10)); - e.gold_cursor = static_cast(strtoul(row[10], nullptr, 10)); - e.silver_cursor = static_cast(strtoul(row[11], nullptr, 10)); - e.copper_cursor = static_cast(strtoul(row[12], nullptr, 10)); - e.radiant_crystals = static_cast(strtoul(row[13], nullptr, 10)); - e.career_radiant_crystals = static_cast(strtoul(row[14], nullptr, 10)); - e.ebon_crystals = static_cast(strtoul(row[15], nullptr, 10)); - e.career_ebon_crystals = static_cast(strtoul(row[16], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.platinum = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.gold = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.silver = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.copper = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.platinum_bank = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.gold_bank = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.silver_bank = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.copper_bank = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.platinum_cursor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.gold_cursor = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.silver_cursor = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.copper_cursor = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.radiant_crystals = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.career_radiant_crystals = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ebon_crystals = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.career_ebon_crystals = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -405,23 +404,23 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterCurrency e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.platinum = static_cast(strtoul(row[1], nullptr, 10)); - e.gold = static_cast(strtoul(row[2], nullptr, 10)); - e.silver = static_cast(strtoul(row[3], nullptr, 10)); - e.copper = static_cast(strtoul(row[4], nullptr, 10)); - e.platinum_bank = static_cast(strtoul(row[5], nullptr, 10)); - e.gold_bank = static_cast(strtoul(row[6], nullptr, 10)); - e.silver_bank = static_cast(strtoul(row[7], nullptr, 10)); - e.copper_bank = static_cast(strtoul(row[8], nullptr, 10)); - e.platinum_cursor = static_cast(strtoul(row[9], nullptr, 10)); - e.gold_cursor = static_cast(strtoul(row[10], nullptr, 10)); - e.silver_cursor = static_cast(strtoul(row[11], nullptr, 10)); - e.copper_cursor = static_cast(strtoul(row[12], nullptr, 10)); - e.radiant_crystals = static_cast(strtoul(row[13], nullptr, 10)); - e.career_radiant_crystals = static_cast(strtoul(row[14], nullptr, 10)); - e.ebon_crystals = static_cast(strtoul(row[15], nullptr, 10)); - e.career_ebon_crystals = static_cast(strtoul(row[16], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.platinum = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.gold = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.silver = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.copper = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.platinum_bank = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.gold_bank = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.silver_bank = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.copper_bank = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.platinum_cursor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.gold_cursor = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.silver_cursor = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.copper_cursor = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.radiant_crystals = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.career_radiant_crystals = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ebon_crystals = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.career_ebon_crystals = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_data_repository.h b/common/repositories/base/base_character_data_repository.h index 7aee66913..2580788f4 100644 --- a/common/repositories/base/base_character_data_repository.h +++ b/common/repositories/base/base_character_data_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterDataRepository { public: struct CharacterData { @@ -524,108 +523,108 @@ public: if (results.RowCount() == 1) { CharacterData e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_id = static_cast(atoi(row[1])); e.name = row[2] ? row[2] : ""; e.last_name = row[3] ? row[3] : ""; e.title = row[4] ? row[4] : ""; e.suffix = row[5] ? row[5] : ""; - e.zone_id = static_cast(strtoul(row[6], nullptr, 10)); - e.zone_instance = static_cast(strtoul(row[7], nullptr, 10)); - e.y = strtof(row[8], nullptr); - e.x = strtof(row[9], nullptr); - e.z = strtof(row[10], nullptr); - e.heading = strtof(row[11], nullptr); - e.gender = static_cast(strtoul(row[12], nullptr, 10)); - e.race = static_cast(strtoul(row[13], nullptr, 10)); - e.class_ = static_cast(strtoul(row[14], nullptr, 10)); - e.level = static_cast(strtoul(row[15], nullptr, 10)); - e.deity = static_cast(strtoul(row[16], nullptr, 10)); - e.birthday = static_cast(strtoul(row[17], nullptr, 10)); - e.last_login = static_cast(strtoul(row[18], nullptr, 10)); - e.time_played = static_cast(strtoul(row[19], nullptr, 10)); - e.level2 = static_cast(strtoul(row[20], nullptr, 10)); - e.anon = static_cast(strtoul(row[21], nullptr, 10)); - e.gm = static_cast(strtoul(row[22], nullptr, 10)); - e.face = static_cast(strtoul(row[23], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[24], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[25], nullptr, 10)); - e.beard = static_cast(strtoul(row[26], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[27], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[28], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[29], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[30], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[31], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[32], nullptr, 10)); - e.ability_time_seconds = static_cast(strtoul(row[33], nullptr, 10)); - e.ability_number = static_cast(strtoul(row[34], nullptr, 10)); - e.ability_time_minutes = static_cast(strtoul(row[35], nullptr, 10)); - e.ability_time_hours = static_cast(strtoul(row[36], nullptr, 10)); - e.exp = static_cast(strtoul(row[37], nullptr, 10)); - e.exp_enabled = static_cast(strtoul(row[38], nullptr, 10)); - e.aa_points_spent = static_cast(strtoul(row[39], nullptr, 10)); - e.aa_exp = static_cast(strtoul(row[40], nullptr, 10)); - e.aa_points = static_cast(strtoul(row[41], nullptr, 10)); - e.group_leadership_exp = static_cast(strtoul(row[42], nullptr, 10)); - e.raid_leadership_exp = static_cast(strtoul(row[43], nullptr, 10)); - e.group_leadership_points = static_cast(strtoul(row[44], nullptr, 10)); - e.raid_leadership_points = static_cast(strtoul(row[45], nullptr, 10)); - e.points = static_cast(strtoul(row[46], nullptr, 10)); - e.cur_hp = static_cast(strtoul(row[47], nullptr, 10)); - e.mana = static_cast(strtoul(row[48], nullptr, 10)); - e.endurance = static_cast(strtoul(row[49], nullptr, 10)); - e.intoxication = static_cast(strtoul(row[50], nullptr, 10)); - e.str = static_cast(strtoul(row[51], nullptr, 10)); - e.sta = static_cast(strtoul(row[52], nullptr, 10)); - e.cha = static_cast(strtoul(row[53], nullptr, 10)); - e.dex = static_cast(strtoul(row[54], nullptr, 10)); - e.int_ = static_cast(strtoul(row[55], nullptr, 10)); - e.agi = static_cast(strtoul(row[56], nullptr, 10)); - e.wis = static_cast(strtoul(row[57], nullptr, 10)); - e.zone_change_count = static_cast(strtoul(row[58], nullptr, 10)); - e.toxicity = static_cast(strtoul(row[59], nullptr, 10)); - e.hunger_level = static_cast(strtoul(row[60], nullptr, 10)); - e.thirst_level = static_cast(strtoul(row[61], nullptr, 10)); - e.ability_up = static_cast(strtoul(row[62], nullptr, 10)); - e.ldon_points_guk = static_cast(strtoul(row[63], nullptr, 10)); - e.ldon_points_mir = static_cast(strtoul(row[64], nullptr, 10)); - e.ldon_points_mmc = static_cast(strtoul(row[65], nullptr, 10)); - e.ldon_points_ruj = static_cast(strtoul(row[66], nullptr, 10)); - e.ldon_points_tak = static_cast(strtoul(row[67], nullptr, 10)); - e.ldon_points_available = static_cast(strtoul(row[68], nullptr, 10)); - e.tribute_time_remaining = static_cast(strtoul(row[69], nullptr, 10)); - e.career_tribute_points = static_cast(strtoul(row[70], nullptr, 10)); - e.tribute_points = static_cast(strtoul(row[71], nullptr, 10)); - e.tribute_active = static_cast(strtoul(row[72], nullptr, 10)); - e.pvp_status = static_cast(strtoul(row[73], nullptr, 10)); - e.pvp_kills = static_cast(strtoul(row[74], nullptr, 10)); - e.pvp_deaths = static_cast(strtoul(row[75], nullptr, 10)); - e.pvp_current_points = static_cast(strtoul(row[76], nullptr, 10)); - e.pvp_career_points = static_cast(strtoul(row[77], nullptr, 10)); - e.pvp_best_kill_streak = static_cast(strtoul(row[78], nullptr, 10)); - e.pvp_worst_death_streak = static_cast(strtoul(row[79], nullptr, 10)); - e.pvp_current_kill_streak = static_cast(strtoul(row[80], nullptr, 10)); - e.pvp2 = static_cast(strtoul(row[81], nullptr, 10)); - e.pvp_type = static_cast(strtoul(row[82], nullptr, 10)); - e.show_helm = static_cast(strtoul(row[83], nullptr, 10)); - e.group_auto_consent = static_cast(strtoul(row[84], nullptr, 10)); - e.raid_auto_consent = static_cast(strtoul(row[85], nullptr, 10)); - e.guild_auto_consent = static_cast(strtoul(row[86], nullptr, 10)); - e.leadership_exp_on = static_cast(strtoul(row[87], nullptr, 10)); - e.RestTimer = static_cast(strtoul(row[88], nullptr, 10)); - e.air_remaining = static_cast(strtoul(row[89], nullptr, 10)); - e.autosplit_enabled = static_cast(strtoul(row[90], nullptr, 10)); - e.lfp = static_cast(strtoul(row[91], nullptr, 10)); - e.lfg = static_cast(strtoul(row[92], nullptr, 10)); + e.zone_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.zone_instance = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.y = row[8] ? strtof(row[8], nullptr) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.z = row[10] ? strtof(row[10], nullptr) : 0; + e.heading = row[11] ? strtof(row[11], nullptr) : 0; + e.gender = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.race = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.class_ = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.deity = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.birthday = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.last_login = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.time_played = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.level2 = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.anon = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.gm = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.face = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.hair_color = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.hair_style = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.beard = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.beard_color = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.eye_color_1 = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.eye_color_2 = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.drakkin_heritage = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.drakkin_tattoo = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.drakkin_details = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.ability_time_seconds = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.ability_number = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.ability_time_minutes = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.ability_time_hours = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.exp = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.exp_enabled = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 1; + e.aa_points_spent = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.aa_exp = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.aa_points = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.group_leadership_exp = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.raid_leadership_exp = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.group_leadership_points = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.raid_leadership_points = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.points = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.cur_hp = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.mana = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.endurance = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.intoxication = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 0; + e.str = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 0; + e.sta = row[52] ? static_cast(strtoul(row[52], nullptr, 10)) : 0; + e.cha = row[53] ? static_cast(strtoul(row[53], nullptr, 10)) : 0; + e.dex = row[54] ? static_cast(strtoul(row[54], nullptr, 10)) : 0; + e.int_ = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; + e.agi = row[56] ? static_cast(strtoul(row[56], nullptr, 10)) : 0; + e.wis = row[57] ? static_cast(strtoul(row[57], nullptr, 10)) : 0; + e.zone_change_count = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.toxicity = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.hunger_level = row[60] ? static_cast(strtoul(row[60], nullptr, 10)) : 0; + e.thirst_level = row[61] ? static_cast(strtoul(row[61], nullptr, 10)) : 0; + e.ability_up = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; + e.ldon_points_guk = row[63] ? static_cast(strtoul(row[63], nullptr, 10)) : 0; + e.ldon_points_mir = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; + e.ldon_points_mmc = row[65] ? static_cast(strtoul(row[65], nullptr, 10)) : 0; + e.ldon_points_ruj = row[66] ? static_cast(strtoul(row[66], nullptr, 10)) : 0; + e.ldon_points_tak = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 0; + e.ldon_points_available = row[68] ? static_cast(strtoul(row[68], nullptr, 10)) : 0; + e.tribute_time_remaining = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 0; + e.career_tribute_points = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 0; + e.tribute_points = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 0; + e.tribute_active = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 0; + e.pvp_status = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 0; + e.pvp_kills = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 0; + e.pvp_deaths = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 0; + e.pvp_current_points = row[76] ? static_cast(strtoul(row[76], nullptr, 10)) : 0; + e.pvp_career_points = row[77] ? static_cast(strtoul(row[77], nullptr, 10)) : 0; + e.pvp_best_kill_streak = row[78] ? static_cast(strtoul(row[78], nullptr, 10)) : 0; + e.pvp_worst_death_streak = row[79] ? static_cast(strtoul(row[79], nullptr, 10)) : 0; + e.pvp_current_kill_streak = row[80] ? static_cast(strtoul(row[80], nullptr, 10)) : 0; + e.pvp2 = row[81] ? static_cast(strtoul(row[81], nullptr, 10)) : 0; + e.pvp_type = row[82] ? static_cast(strtoul(row[82], nullptr, 10)) : 0; + e.show_helm = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; + e.group_auto_consent = row[84] ? static_cast(strtoul(row[84], nullptr, 10)) : 0; + e.raid_auto_consent = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; + e.guild_auto_consent = row[86] ? static_cast(strtoul(row[86], nullptr, 10)) : 0; + e.leadership_exp_on = row[87] ? static_cast(strtoul(row[87], nullptr, 10)) : 0; + e.RestTimer = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.air_remaining = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.autosplit_enabled = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; + e.lfp = row[91] ? static_cast(strtoul(row[91], nullptr, 10)) : 0; + e.lfg = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; e.mailkey = row[93] ? row[93] : ""; - e.xtargets = static_cast(strtoul(row[94], nullptr, 10)); + e.xtargets = row[94] ? static_cast(strtoul(row[94], nullptr, 10)) : 5; e.firstlogon = static_cast(atoi(row[95])); - e.e_aa_effects = static_cast(strtoul(row[96], nullptr, 10)); - e.e_percent_to_aa = static_cast(strtoul(row[97], nullptr, 10)); - e.e_expended_aa_spent = static_cast(strtoul(row[98], nullptr, 10)); - e.aa_points_spent_old = static_cast(strtoul(row[99], nullptr, 10)); - e.aa_points_old = static_cast(strtoul(row[100], nullptr, 10)); - e.e_last_invsnapshot = static_cast(strtoul(row[101], nullptr, 10)); + e.e_aa_effects = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; + e.e_percent_to_aa = row[97] ? static_cast(strtoul(row[97], nullptr, 10)) : 0; + e.e_expended_aa_spent = row[98] ? static_cast(strtoul(row[98], nullptr, 10)) : 0; + e.aa_points_spent_old = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; + e.aa_points_old = row[100] ? static_cast(strtoul(row[100], nullptr, 10)) : 0; + e.e_last_invsnapshot = row[101] ? static_cast(strtoul(row[101], nullptr, 10)) : 0; e.deleted_at = strtoll(row[102] ? row[102] : "-1", nullptr, 10); return e; @@ -1051,108 +1050,108 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterData e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_id = static_cast(atoi(row[1])); e.name = row[2] ? row[2] : ""; e.last_name = row[3] ? row[3] : ""; e.title = row[4] ? row[4] : ""; e.suffix = row[5] ? row[5] : ""; - e.zone_id = static_cast(strtoul(row[6], nullptr, 10)); - e.zone_instance = static_cast(strtoul(row[7], nullptr, 10)); - e.y = strtof(row[8], nullptr); - e.x = strtof(row[9], nullptr); - e.z = strtof(row[10], nullptr); - e.heading = strtof(row[11], nullptr); - e.gender = static_cast(strtoul(row[12], nullptr, 10)); - e.race = static_cast(strtoul(row[13], nullptr, 10)); - e.class_ = static_cast(strtoul(row[14], nullptr, 10)); - e.level = static_cast(strtoul(row[15], nullptr, 10)); - e.deity = static_cast(strtoul(row[16], nullptr, 10)); - e.birthday = static_cast(strtoul(row[17], nullptr, 10)); - e.last_login = static_cast(strtoul(row[18], nullptr, 10)); - e.time_played = static_cast(strtoul(row[19], nullptr, 10)); - e.level2 = static_cast(strtoul(row[20], nullptr, 10)); - e.anon = static_cast(strtoul(row[21], nullptr, 10)); - e.gm = static_cast(strtoul(row[22], nullptr, 10)); - e.face = static_cast(strtoul(row[23], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[24], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[25], nullptr, 10)); - e.beard = static_cast(strtoul(row[26], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[27], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[28], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[29], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[30], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[31], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[32], nullptr, 10)); - e.ability_time_seconds = static_cast(strtoul(row[33], nullptr, 10)); - e.ability_number = static_cast(strtoul(row[34], nullptr, 10)); - e.ability_time_minutes = static_cast(strtoul(row[35], nullptr, 10)); - e.ability_time_hours = static_cast(strtoul(row[36], nullptr, 10)); - e.exp = static_cast(strtoul(row[37], nullptr, 10)); - e.exp_enabled = static_cast(strtoul(row[38], nullptr, 10)); - e.aa_points_spent = static_cast(strtoul(row[39], nullptr, 10)); - e.aa_exp = static_cast(strtoul(row[40], nullptr, 10)); - e.aa_points = static_cast(strtoul(row[41], nullptr, 10)); - e.group_leadership_exp = static_cast(strtoul(row[42], nullptr, 10)); - e.raid_leadership_exp = static_cast(strtoul(row[43], nullptr, 10)); - e.group_leadership_points = static_cast(strtoul(row[44], nullptr, 10)); - e.raid_leadership_points = static_cast(strtoul(row[45], nullptr, 10)); - e.points = static_cast(strtoul(row[46], nullptr, 10)); - e.cur_hp = static_cast(strtoul(row[47], nullptr, 10)); - e.mana = static_cast(strtoul(row[48], nullptr, 10)); - e.endurance = static_cast(strtoul(row[49], nullptr, 10)); - e.intoxication = static_cast(strtoul(row[50], nullptr, 10)); - e.str = static_cast(strtoul(row[51], nullptr, 10)); - e.sta = static_cast(strtoul(row[52], nullptr, 10)); - e.cha = static_cast(strtoul(row[53], nullptr, 10)); - e.dex = static_cast(strtoul(row[54], nullptr, 10)); - e.int_ = static_cast(strtoul(row[55], nullptr, 10)); - e.agi = static_cast(strtoul(row[56], nullptr, 10)); - e.wis = static_cast(strtoul(row[57], nullptr, 10)); - e.zone_change_count = static_cast(strtoul(row[58], nullptr, 10)); - e.toxicity = static_cast(strtoul(row[59], nullptr, 10)); - e.hunger_level = static_cast(strtoul(row[60], nullptr, 10)); - e.thirst_level = static_cast(strtoul(row[61], nullptr, 10)); - e.ability_up = static_cast(strtoul(row[62], nullptr, 10)); - e.ldon_points_guk = static_cast(strtoul(row[63], nullptr, 10)); - e.ldon_points_mir = static_cast(strtoul(row[64], nullptr, 10)); - e.ldon_points_mmc = static_cast(strtoul(row[65], nullptr, 10)); - e.ldon_points_ruj = static_cast(strtoul(row[66], nullptr, 10)); - e.ldon_points_tak = static_cast(strtoul(row[67], nullptr, 10)); - e.ldon_points_available = static_cast(strtoul(row[68], nullptr, 10)); - e.tribute_time_remaining = static_cast(strtoul(row[69], nullptr, 10)); - e.career_tribute_points = static_cast(strtoul(row[70], nullptr, 10)); - e.tribute_points = static_cast(strtoul(row[71], nullptr, 10)); - e.tribute_active = static_cast(strtoul(row[72], nullptr, 10)); - e.pvp_status = static_cast(strtoul(row[73], nullptr, 10)); - e.pvp_kills = static_cast(strtoul(row[74], nullptr, 10)); - e.pvp_deaths = static_cast(strtoul(row[75], nullptr, 10)); - e.pvp_current_points = static_cast(strtoul(row[76], nullptr, 10)); - e.pvp_career_points = static_cast(strtoul(row[77], nullptr, 10)); - e.pvp_best_kill_streak = static_cast(strtoul(row[78], nullptr, 10)); - e.pvp_worst_death_streak = static_cast(strtoul(row[79], nullptr, 10)); - e.pvp_current_kill_streak = static_cast(strtoul(row[80], nullptr, 10)); - e.pvp2 = static_cast(strtoul(row[81], nullptr, 10)); - e.pvp_type = static_cast(strtoul(row[82], nullptr, 10)); - e.show_helm = static_cast(strtoul(row[83], nullptr, 10)); - e.group_auto_consent = static_cast(strtoul(row[84], nullptr, 10)); - e.raid_auto_consent = static_cast(strtoul(row[85], nullptr, 10)); - e.guild_auto_consent = static_cast(strtoul(row[86], nullptr, 10)); - e.leadership_exp_on = static_cast(strtoul(row[87], nullptr, 10)); - e.RestTimer = static_cast(strtoul(row[88], nullptr, 10)); - e.air_remaining = static_cast(strtoul(row[89], nullptr, 10)); - e.autosplit_enabled = static_cast(strtoul(row[90], nullptr, 10)); - e.lfp = static_cast(strtoul(row[91], nullptr, 10)); - e.lfg = static_cast(strtoul(row[92], nullptr, 10)); + e.zone_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.zone_instance = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.y = row[8] ? strtof(row[8], nullptr) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.z = row[10] ? strtof(row[10], nullptr) : 0; + e.heading = row[11] ? strtof(row[11], nullptr) : 0; + e.gender = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.race = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.class_ = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.deity = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.birthday = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.last_login = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.time_played = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.level2 = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.anon = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.gm = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.face = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.hair_color = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.hair_style = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.beard = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.beard_color = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.eye_color_1 = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.eye_color_2 = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.drakkin_heritage = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.drakkin_tattoo = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.drakkin_details = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.ability_time_seconds = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.ability_number = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.ability_time_minutes = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.ability_time_hours = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.exp = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.exp_enabled = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 1; + e.aa_points_spent = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.aa_exp = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.aa_points = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.group_leadership_exp = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.raid_leadership_exp = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.group_leadership_points = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.raid_leadership_points = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.points = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.cur_hp = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.mana = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.endurance = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.intoxication = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 0; + e.str = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 0; + e.sta = row[52] ? static_cast(strtoul(row[52], nullptr, 10)) : 0; + e.cha = row[53] ? static_cast(strtoul(row[53], nullptr, 10)) : 0; + e.dex = row[54] ? static_cast(strtoul(row[54], nullptr, 10)) : 0; + e.int_ = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; + e.agi = row[56] ? static_cast(strtoul(row[56], nullptr, 10)) : 0; + e.wis = row[57] ? static_cast(strtoul(row[57], nullptr, 10)) : 0; + e.zone_change_count = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.toxicity = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.hunger_level = row[60] ? static_cast(strtoul(row[60], nullptr, 10)) : 0; + e.thirst_level = row[61] ? static_cast(strtoul(row[61], nullptr, 10)) : 0; + e.ability_up = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; + e.ldon_points_guk = row[63] ? static_cast(strtoul(row[63], nullptr, 10)) : 0; + e.ldon_points_mir = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; + e.ldon_points_mmc = row[65] ? static_cast(strtoul(row[65], nullptr, 10)) : 0; + e.ldon_points_ruj = row[66] ? static_cast(strtoul(row[66], nullptr, 10)) : 0; + e.ldon_points_tak = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 0; + e.ldon_points_available = row[68] ? static_cast(strtoul(row[68], nullptr, 10)) : 0; + e.tribute_time_remaining = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 0; + e.career_tribute_points = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 0; + e.tribute_points = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 0; + e.tribute_active = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 0; + e.pvp_status = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 0; + e.pvp_kills = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 0; + e.pvp_deaths = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 0; + e.pvp_current_points = row[76] ? static_cast(strtoul(row[76], nullptr, 10)) : 0; + e.pvp_career_points = row[77] ? static_cast(strtoul(row[77], nullptr, 10)) : 0; + e.pvp_best_kill_streak = row[78] ? static_cast(strtoul(row[78], nullptr, 10)) : 0; + e.pvp_worst_death_streak = row[79] ? static_cast(strtoul(row[79], nullptr, 10)) : 0; + e.pvp_current_kill_streak = row[80] ? static_cast(strtoul(row[80], nullptr, 10)) : 0; + e.pvp2 = row[81] ? static_cast(strtoul(row[81], nullptr, 10)) : 0; + e.pvp_type = row[82] ? static_cast(strtoul(row[82], nullptr, 10)) : 0; + e.show_helm = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; + e.group_auto_consent = row[84] ? static_cast(strtoul(row[84], nullptr, 10)) : 0; + e.raid_auto_consent = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; + e.guild_auto_consent = row[86] ? static_cast(strtoul(row[86], nullptr, 10)) : 0; + e.leadership_exp_on = row[87] ? static_cast(strtoul(row[87], nullptr, 10)) : 0; + e.RestTimer = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.air_remaining = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.autosplit_enabled = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; + e.lfp = row[91] ? static_cast(strtoul(row[91], nullptr, 10)) : 0; + e.lfg = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; e.mailkey = row[93] ? row[93] : ""; - e.xtargets = static_cast(strtoul(row[94], nullptr, 10)); + e.xtargets = row[94] ? static_cast(strtoul(row[94], nullptr, 10)) : 5; e.firstlogon = static_cast(atoi(row[95])); - e.e_aa_effects = static_cast(strtoul(row[96], nullptr, 10)); - e.e_percent_to_aa = static_cast(strtoul(row[97], nullptr, 10)); - e.e_expended_aa_spent = static_cast(strtoul(row[98], nullptr, 10)); - e.aa_points_spent_old = static_cast(strtoul(row[99], nullptr, 10)); - e.aa_points_old = static_cast(strtoul(row[100], nullptr, 10)); - e.e_last_invsnapshot = static_cast(strtoul(row[101], nullptr, 10)); + e.e_aa_effects = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; + e.e_percent_to_aa = row[97] ? static_cast(strtoul(row[97], nullptr, 10)) : 0; + e.e_expended_aa_spent = row[98] ? static_cast(strtoul(row[98], nullptr, 10)) : 0; + e.aa_points_spent_old = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; + e.aa_points_old = row[100] ? static_cast(strtoul(row[100], nullptr, 10)) : 0; + e.e_last_invsnapshot = row[101] ? static_cast(strtoul(row[101], nullptr, 10)) : 0; e.deleted_at = strtoll(row[102] ? row[102] : "-1", nullptr, 10); all_entries.push_back(e); @@ -1178,108 +1177,108 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterData e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_id = static_cast(atoi(row[1])); e.name = row[2] ? row[2] : ""; e.last_name = row[3] ? row[3] : ""; e.title = row[4] ? row[4] : ""; e.suffix = row[5] ? row[5] : ""; - e.zone_id = static_cast(strtoul(row[6], nullptr, 10)); - e.zone_instance = static_cast(strtoul(row[7], nullptr, 10)); - e.y = strtof(row[8], nullptr); - e.x = strtof(row[9], nullptr); - e.z = strtof(row[10], nullptr); - e.heading = strtof(row[11], nullptr); - e.gender = static_cast(strtoul(row[12], nullptr, 10)); - e.race = static_cast(strtoul(row[13], nullptr, 10)); - e.class_ = static_cast(strtoul(row[14], nullptr, 10)); - e.level = static_cast(strtoul(row[15], nullptr, 10)); - e.deity = static_cast(strtoul(row[16], nullptr, 10)); - e.birthday = static_cast(strtoul(row[17], nullptr, 10)); - e.last_login = static_cast(strtoul(row[18], nullptr, 10)); - e.time_played = static_cast(strtoul(row[19], nullptr, 10)); - e.level2 = static_cast(strtoul(row[20], nullptr, 10)); - e.anon = static_cast(strtoul(row[21], nullptr, 10)); - e.gm = static_cast(strtoul(row[22], nullptr, 10)); - e.face = static_cast(strtoul(row[23], nullptr, 10)); - e.hair_color = static_cast(strtoul(row[24], nullptr, 10)); - e.hair_style = static_cast(strtoul(row[25], nullptr, 10)); - e.beard = static_cast(strtoul(row[26], nullptr, 10)); - e.beard_color = static_cast(strtoul(row[27], nullptr, 10)); - e.eye_color_1 = static_cast(strtoul(row[28], nullptr, 10)); - e.eye_color_2 = static_cast(strtoul(row[29], nullptr, 10)); - e.drakkin_heritage = static_cast(strtoul(row[30], nullptr, 10)); - e.drakkin_tattoo = static_cast(strtoul(row[31], nullptr, 10)); - e.drakkin_details = static_cast(strtoul(row[32], nullptr, 10)); - e.ability_time_seconds = static_cast(strtoul(row[33], nullptr, 10)); - e.ability_number = static_cast(strtoul(row[34], nullptr, 10)); - e.ability_time_minutes = static_cast(strtoul(row[35], nullptr, 10)); - e.ability_time_hours = static_cast(strtoul(row[36], nullptr, 10)); - e.exp = static_cast(strtoul(row[37], nullptr, 10)); - e.exp_enabled = static_cast(strtoul(row[38], nullptr, 10)); - e.aa_points_spent = static_cast(strtoul(row[39], nullptr, 10)); - e.aa_exp = static_cast(strtoul(row[40], nullptr, 10)); - e.aa_points = static_cast(strtoul(row[41], nullptr, 10)); - e.group_leadership_exp = static_cast(strtoul(row[42], nullptr, 10)); - e.raid_leadership_exp = static_cast(strtoul(row[43], nullptr, 10)); - e.group_leadership_points = static_cast(strtoul(row[44], nullptr, 10)); - e.raid_leadership_points = static_cast(strtoul(row[45], nullptr, 10)); - e.points = static_cast(strtoul(row[46], nullptr, 10)); - e.cur_hp = static_cast(strtoul(row[47], nullptr, 10)); - e.mana = static_cast(strtoul(row[48], nullptr, 10)); - e.endurance = static_cast(strtoul(row[49], nullptr, 10)); - e.intoxication = static_cast(strtoul(row[50], nullptr, 10)); - e.str = static_cast(strtoul(row[51], nullptr, 10)); - e.sta = static_cast(strtoul(row[52], nullptr, 10)); - e.cha = static_cast(strtoul(row[53], nullptr, 10)); - e.dex = static_cast(strtoul(row[54], nullptr, 10)); - e.int_ = static_cast(strtoul(row[55], nullptr, 10)); - e.agi = static_cast(strtoul(row[56], nullptr, 10)); - e.wis = static_cast(strtoul(row[57], nullptr, 10)); - e.zone_change_count = static_cast(strtoul(row[58], nullptr, 10)); - e.toxicity = static_cast(strtoul(row[59], nullptr, 10)); - e.hunger_level = static_cast(strtoul(row[60], nullptr, 10)); - e.thirst_level = static_cast(strtoul(row[61], nullptr, 10)); - e.ability_up = static_cast(strtoul(row[62], nullptr, 10)); - e.ldon_points_guk = static_cast(strtoul(row[63], nullptr, 10)); - e.ldon_points_mir = static_cast(strtoul(row[64], nullptr, 10)); - e.ldon_points_mmc = static_cast(strtoul(row[65], nullptr, 10)); - e.ldon_points_ruj = static_cast(strtoul(row[66], nullptr, 10)); - e.ldon_points_tak = static_cast(strtoul(row[67], nullptr, 10)); - e.ldon_points_available = static_cast(strtoul(row[68], nullptr, 10)); - e.tribute_time_remaining = static_cast(strtoul(row[69], nullptr, 10)); - e.career_tribute_points = static_cast(strtoul(row[70], nullptr, 10)); - e.tribute_points = static_cast(strtoul(row[71], nullptr, 10)); - e.tribute_active = static_cast(strtoul(row[72], nullptr, 10)); - e.pvp_status = static_cast(strtoul(row[73], nullptr, 10)); - e.pvp_kills = static_cast(strtoul(row[74], nullptr, 10)); - e.pvp_deaths = static_cast(strtoul(row[75], nullptr, 10)); - e.pvp_current_points = static_cast(strtoul(row[76], nullptr, 10)); - e.pvp_career_points = static_cast(strtoul(row[77], nullptr, 10)); - e.pvp_best_kill_streak = static_cast(strtoul(row[78], nullptr, 10)); - e.pvp_worst_death_streak = static_cast(strtoul(row[79], nullptr, 10)); - e.pvp_current_kill_streak = static_cast(strtoul(row[80], nullptr, 10)); - e.pvp2 = static_cast(strtoul(row[81], nullptr, 10)); - e.pvp_type = static_cast(strtoul(row[82], nullptr, 10)); - e.show_helm = static_cast(strtoul(row[83], nullptr, 10)); - e.group_auto_consent = static_cast(strtoul(row[84], nullptr, 10)); - e.raid_auto_consent = static_cast(strtoul(row[85], nullptr, 10)); - e.guild_auto_consent = static_cast(strtoul(row[86], nullptr, 10)); - e.leadership_exp_on = static_cast(strtoul(row[87], nullptr, 10)); - e.RestTimer = static_cast(strtoul(row[88], nullptr, 10)); - e.air_remaining = static_cast(strtoul(row[89], nullptr, 10)); - e.autosplit_enabled = static_cast(strtoul(row[90], nullptr, 10)); - e.lfp = static_cast(strtoul(row[91], nullptr, 10)); - e.lfg = static_cast(strtoul(row[92], nullptr, 10)); + e.zone_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.zone_instance = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.y = row[8] ? strtof(row[8], nullptr) : 0; + e.x = row[9] ? strtof(row[9], nullptr) : 0; + e.z = row[10] ? strtof(row[10], nullptr) : 0; + e.heading = row[11] ? strtof(row[11], nullptr) : 0; + e.gender = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.race = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.class_ = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.deity = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.birthday = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.last_login = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.time_played = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.level2 = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.anon = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.gm = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.face = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.hair_color = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.hair_style = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.beard = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.beard_color = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.eye_color_1 = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; + e.eye_color_2 = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 0; + e.drakkin_heritage = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.drakkin_tattoo = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.drakkin_details = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.ability_time_seconds = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.ability_number = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.ability_time_minutes = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 0; + e.ability_time_hours = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 0; + e.exp = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.exp_enabled = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 1; + e.aa_points_spent = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.aa_exp = row[40] ? static_cast(strtoul(row[40], nullptr, 10)) : 0; + e.aa_points = row[41] ? static_cast(strtoul(row[41], nullptr, 10)) : 0; + e.group_leadership_exp = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.raid_leadership_exp = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.group_leadership_points = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.raid_leadership_points = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.points = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.cur_hp = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.mana = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.endurance = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.intoxication = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 0; + e.str = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 0; + e.sta = row[52] ? static_cast(strtoul(row[52], nullptr, 10)) : 0; + e.cha = row[53] ? static_cast(strtoul(row[53], nullptr, 10)) : 0; + e.dex = row[54] ? static_cast(strtoul(row[54], nullptr, 10)) : 0; + e.int_ = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; + e.agi = row[56] ? static_cast(strtoul(row[56], nullptr, 10)) : 0; + e.wis = row[57] ? static_cast(strtoul(row[57], nullptr, 10)) : 0; + e.zone_change_count = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.toxicity = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.hunger_level = row[60] ? static_cast(strtoul(row[60], nullptr, 10)) : 0; + e.thirst_level = row[61] ? static_cast(strtoul(row[61], nullptr, 10)) : 0; + e.ability_up = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; + e.ldon_points_guk = row[63] ? static_cast(strtoul(row[63], nullptr, 10)) : 0; + e.ldon_points_mir = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; + e.ldon_points_mmc = row[65] ? static_cast(strtoul(row[65], nullptr, 10)) : 0; + e.ldon_points_ruj = row[66] ? static_cast(strtoul(row[66], nullptr, 10)) : 0; + e.ldon_points_tak = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 0; + e.ldon_points_available = row[68] ? static_cast(strtoul(row[68], nullptr, 10)) : 0; + e.tribute_time_remaining = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 0; + e.career_tribute_points = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 0; + e.tribute_points = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 0; + e.tribute_active = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 0; + e.pvp_status = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 0; + e.pvp_kills = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 0; + e.pvp_deaths = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 0; + e.pvp_current_points = row[76] ? static_cast(strtoul(row[76], nullptr, 10)) : 0; + e.pvp_career_points = row[77] ? static_cast(strtoul(row[77], nullptr, 10)) : 0; + e.pvp_best_kill_streak = row[78] ? static_cast(strtoul(row[78], nullptr, 10)) : 0; + e.pvp_worst_death_streak = row[79] ? static_cast(strtoul(row[79], nullptr, 10)) : 0; + e.pvp_current_kill_streak = row[80] ? static_cast(strtoul(row[80], nullptr, 10)) : 0; + e.pvp2 = row[81] ? static_cast(strtoul(row[81], nullptr, 10)) : 0; + e.pvp_type = row[82] ? static_cast(strtoul(row[82], nullptr, 10)) : 0; + e.show_helm = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; + e.group_auto_consent = row[84] ? static_cast(strtoul(row[84], nullptr, 10)) : 0; + e.raid_auto_consent = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; + e.guild_auto_consent = row[86] ? static_cast(strtoul(row[86], nullptr, 10)) : 0; + e.leadership_exp_on = row[87] ? static_cast(strtoul(row[87], nullptr, 10)) : 0; + e.RestTimer = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.air_remaining = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.autosplit_enabled = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; + e.lfp = row[91] ? static_cast(strtoul(row[91], nullptr, 10)) : 0; + e.lfg = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; e.mailkey = row[93] ? row[93] : ""; - e.xtargets = static_cast(strtoul(row[94], nullptr, 10)); + e.xtargets = row[94] ? static_cast(strtoul(row[94], nullptr, 10)) : 5; e.firstlogon = static_cast(atoi(row[95])); - e.e_aa_effects = static_cast(strtoul(row[96], nullptr, 10)); - e.e_percent_to_aa = static_cast(strtoul(row[97], nullptr, 10)); - e.e_expended_aa_spent = static_cast(strtoul(row[98], nullptr, 10)); - e.aa_points_spent_old = static_cast(strtoul(row[99], nullptr, 10)); - e.aa_points_old = static_cast(strtoul(row[100], nullptr, 10)); - e.e_last_invsnapshot = static_cast(strtoul(row[101], nullptr, 10)); + e.e_aa_effects = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; + e.e_percent_to_aa = row[97] ? static_cast(strtoul(row[97], nullptr, 10)) : 0; + e.e_expended_aa_spent = row[98] ? static_cast(strtoul(row[98], nullptr, 10)) : 0; + e.aa_points_spent_old = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; + e.aa_points_old = row[100] ? static_cast(strtoul(row[100], nullptr, 10)) : 0; + e.e_last_invsnapshot = row[101] ? static_cast(strtoul(row[101], nullptr, 10)) : 0; e.deleted_at = strtoll(row[102] ? row[102] : "-1", nullptr, 10); all_entries.push_back(e); diff --git a/common/repositories/base/base_character_disciplines_repository.h b/common/repositories/base/base_character_disciplines_repository.h index 23796c2a3..931d522f9 100644 --- a/common/repositories/base/base_character_disciplines_repository.h +++ b/common/repositories/base/base_character_disciplines_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterDisciplinesRepository { public: struct CharacterDisciplines { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterDisciplines e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.disc_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.disc_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -252,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterDisciplines e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.disc_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.disc_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -279,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterDisciplines e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.disc_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.disc_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_exp_modifiers_repository.h b/common/repositories/base/base_character_exp_modifiers_repository.h index 034316b19..5a18cd9e3 100644 --- a/common/repositories/base/base_character_exp_modifiers_repository.h +++ b/common/repositories/base/base_character_exp_modifiers_repository.h @@ -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_EXP_MODIFIERS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_exp_modifiers_id ) ); @@ -133,8 +134,8 @@ public: e.character_id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); e.instance_version = static_cast(atoi(row[2])); - e.aa_modifier = strtof(row[3], nullptr); - e.exp_modifier = strtof(row[4], nullptr); + e.aa_modifier = row[3] ? strtof(row[3], nullptr) : 0; + e.exp_modifier = row[4] ? strtof(row[4], nullptr) : 0; return e; } @@ -269,8 +270,8 @@ public: e.character_id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); e.instance_version = static_cast(atoi(row[2])); - e.aa_modifier = strtof(row[3], nullptr); - e.exp_modifier = strtof(row[4], nullptr); + e.aa_modifier = row[3] ? strtof(row[3], nullptr) : 0; + e.exp_modifier = row[4] ? strtof(row[4], nullptr) : 0; all_entries.push_back(e); } @@ -298,8 +299,8 @@ public: e.character_id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); e.instance_version = static_cast(atoi(row[2])); - e.aa_modifier = strtof(row[3], nullptr); - e.exp_modifier = strtof(row[4], nullptr); + e.aa_modifier = row[3] ? strtof(row[3], nullptr) : 0; + e.exp_modifier = row[4] ? strtof(row[4], nullptr) : 0; all_entries.push_back(e); } @@ -358,6 +359,70 @@ 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 CharacterExpModifiers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_version)); + v.push_back(std::to_string(e.aa_modifier)); + v.push_back(std::to_string(e.exp_modifier)); + + 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.character_id)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_version)); + v.push_back(std::to_string(e.aa_modifier)); + v.push_back(std::to_string(e.exp_modifier)); + + 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_CHARACTER_EXP_MODIFIERS_REPOSITORY_H diff --git a/common/repositories/base/base_character_expedition_lockouts_repository.h b/common/repositories/base/base_character_expedition_lockouts_repository.h index 1a5489b87..35d34502a 100644 --- a/common/repositories/base/base_character_expedition_lockouts_repository.h +++ b/common/repositories/base/base_character_expedition_lockouts_repository.h @@ -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_EXPEDITION_LOCKOUTS_REPOSITORY_H @@ -128,8 +128,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_expedition_lockouts_id ) ); @@ -138,12 +139,12 @@ public: if (results.RowCount() == 1) { CharacterExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.expedition_name = row[2] ? row[2] : ""; e.event_name = row[3] ? row[3] : ""; e.expire_time = strtoll(row[4] ? row[4] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.from_expedition_uuid = row[6] ? row[6] : ""; return e; @@ -281,12 +282,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.expedition_name = row[2] ? row[2] : ""; e.event_name = row[3] ? row[3] : ""; e.expire_time = strtoll(row[4] ? row[4] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.from_expedition_uuid = row[6] ? row[6] : ""; all_entries.push_back(e); @@ -312,12 +313,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.expedition_name = row[2] ? row[2] : ""; e.event_name = row[3] ? row[3] : ""; e.expire_time = strtoll(row[4] ? row[4] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.from_expedition_uuid = row[6] ? row[6] : ""; all_entries.push_back(e); @@ -377,6 +378,74 @@ 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 CharacterExpeditionLockouts &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.character_id)); + v.push_back("'" + Strings::Escape(e.expedition_name) + "'"); + v.push_back("'" + Strings::Escape(e.event_name) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back(std::to_string(e.duration)); + v.push_back("'" + Strings::Escape(e.from_expedition_uuid) + "'"); + + 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(std::to_string(e.character_id)); + v.push_back("'" + Strings::Escape(e.expedition_name) + "'"); + v.push_back("'" + Strings::Escape(e.event_name) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back(std::to_string(e.duration)); + v.push_back("'" + Strings::Escape(e.from_expedition_uuid) + "'"); + + 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_CHARACTER_EXPEDITION_LOCKOUTS_REPOSITORY_H diff --git a/common/repositories/base/base_character_inspect_messages_repository.h b/common/repositories/base/base_character_inspect_messages_repository.h index 78d2ea904..b20e510d2 100644 --- a/common/repositories/base/base_character_inspect_messages_repository.h +++ b/common/repositories/base/base_character_inspect_messages_repository.h @@ -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_INSPECT_MESSAGES_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_inspect_messages_id ) ); @@ -118,7 +119,7 @@ public: if (results.RowCount() == 1) { CharacterInspectMessages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.inspect_message = row[1] ? row[1] : ""; return e; @@ -242,7 +243,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterInspectMessages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.inspect_message = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -268,7 +269,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterInspectMessages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.inspect_message = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -328,6 +329,64 @@ 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 CharacterInspectMessages &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.inspect_message) + "'"); + + 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.inspect_message) + "'"); + + 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_CHARACTER_INSPECT_MESSAGES_REPOSITORY_H diff --git a/common/repositories/base/base_character_instance_safereturns_repository.h b/common/repositories/base/base_character_instance_safereturns_repository.h index e8f7faa4b..55c5588d8 100644 --- a/common/repositories/base/base_character_instance_safereturns_repository.h +++ b/common/repositories/base/base_character_instance_safereturns_repository.h @@ -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_INSTANCE_SAFERETURNS_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_instance_safereturns_id ) ); @@ -146,15 +147,15 @@ public: if (results.RowCount() == 1) { CharacterInstanceSafereturns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); e.safe_zone_id = static_cast(atoi(row[4])); - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; return e; } @@ -297,15 +298,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterInstanceSafereturns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); e.safe_zone_id = static_cast(atoi(row[4])); - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; all_entries.push_back(e); } @@ -330,15 +331,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterInstanceSafereturns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.instance_zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); e.safe_zone_id = static_cast(atoi(row[4])); - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; all_entries.push_back(e); } @@ -397,6 +398,78 @@ 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 CharacterInstanceSafereturns &e + ) + { + std::vector 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.instance_zone_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.safe_zone_id)); + v.push_back(std::to_string(e.safe_x)); + v.push_back(std::to_string(e.safe_y)); + v.push_back(std::to_string(e.safe_z)); + v.push_back(std::to_string(e.safe_heading)); + + 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(std::to_string(e.character_id)); + v.push_back(std::to_string(e.instance_zone_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.safe_zone_id)); + v.push_back(std::to_string(e.safe_x)); + v.push_back(std::to_string(e.safe_y)); + v.push_back(std::to_string(e.safe_z)); + v.push_back(std::to_string(e.safe_heading)); + + 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_CHARACTER_INSTANCE_SAFERETURNS_REPOSITORY_H diff --git a/common/repositories/base/base_character_item_recast_repository.h b/common/repositories/base/base_character_item_recast_repository.h index 1784a3b30..3e16755b6 100644 --- a/common/repositories/base/base_character_item_recast_repository.h +++ b/common/repositories/base/base_character_item_recast_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterItemRecastRepository { public: struct CharacterItemRecast { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterItemRecast e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.recast_type = static_cast(strtoul(row[1], nullptr, 10)); - e.timestamp = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.recast_type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.timestamp = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -252,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterItemRecast e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.recast_type = static_cast(strtoul(row[1], nullptr, 10)); - e.timestamp = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.recast_type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.timestamp = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -279,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterItemRecast e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.recast_type = static_cast(strtoul(row[1], nullptr, 10)); - e.timestamp = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.recast_type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.timestamp = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_languages_repository.h b/common/repositories/base/base_character_languages_repository.h index f51c8dc71..7942d80f5 100644 --- a/common/repositories/base/base_character_languages_repository.h +++ b/common/repositories/base/base_character_languages_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterLanguagesRepository { public: struct CharacterLanguages { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterLanguages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.lang_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lang_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -251,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterLanguages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.lang_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lang_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -278,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterLanguages e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.lang_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lang_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_leadership_abilities_repository.h b/common/repositories/base/base_character_leadership_abilities_repository.h index cca170f2f..05baf85e8 100644 --- a/common/repositories/base/base_character_leadership_abilities_repository.h +++ b/common/repositories/base/base_character_leadership_abilities_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterLeadershipAbilitiesRepository { public: struct CharacterLeadershipAbilities { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterLeadershipAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -252,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterLeadershipAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -279,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterLeadershipAbilities e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.rank = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_material_repository.h b/common/repositories/base/base_character_material_repository.h index fa1f55425..3f9d8a8cb 100644 --- a/common/repositories/base/base_character_material_repository.h +++ b/common/repositories/base/base_character_material_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterMaterialRepository { public: struct CharacterMaterial { @@ -140,13 +139,13 @@ public: if (results.RowCount() == 1) { CharacterMaterial e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.blue = static_cast(strtoul(row[2], nullptr, 10)); - e.green = static_cast(strtoul(row[3], nullptr, 10)); - e.red = static_cast(strtoul(row[4], nullptr, 10)); - e.use_tint = static_cast(strtoul(row[5], nullptr, 10)); - e.color = static_cast(strtoul(row[6], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.blue = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.green = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.red = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.use_tint = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.color = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; return e; } @@ -283,13 +282,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterMaterial e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.blue = static_cast(strtoul(row[2], nullptr, 10)); - e.green = static_cast(strtoul(row[3], nullptr, 10)); - e.red = static_cast(strtoul(row[4], nullptr, 10)); - e.use_tint = static_cast(strtoul(row[5], nullptr, 10)); - e.color = static_cast(strtoul(row[6], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.blue = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.green = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.red = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.use_tint = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.color = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -314,13 +313,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterMaterial e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); - e.blue = static_cast(strtoul(row[2], nullptr, 10)); - e.green = static_cast(strtoul(row[3], nullptr, 10)); - e.red = static_cast(strtoul(row[4], nullptr, 10)); - e.use_tint = static_cast(strtoul(row[5], nullptr, 10)); - e.color = static_cast(strtoul(row[6], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.blue = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.green = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.red = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.use_tint = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.color = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_memmed_spells_repository.h b/common/repositories/base/base_character_memmed_spells_repository.h index b8c8c19ac..440b40583 100644 --- a/common/repositories/base/base_character_memmed_spells_repository.h +++ b/common/repositories/base/base_character_memmed_spells_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterMemmedSpellsRepository { public: struct CharacterMemmedSpells { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterMemmedSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -252,9 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterMemmedSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -279,9 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterMemmedSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_peqzone_flags_repository.h b/common/repositories/base/base_character_peqzone_flags_repository.h index fc83278b1..3ecd5bfc6 100644 --- a/common/repositories/base/base_character_peqzone_flags_repository.h +++ b/common/repositories/base/base_character_peqzone_flags_repository.h @@ -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_PEQZONE_FLAGS_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_peqzone_flags_id ) ); @@ -328,6 +329,64 @@ 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 CharacterPeqzoneFlags &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zone_id)); + + 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(std::to_string(e.zone_id)); + + 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_CHARACTER_PEQZONE_FLAGS_REPOSITORY_H diff --git a/common/repositories/base/base_character_pet_buffs_repository.h b/common/repositories/base/base_character_pet_buffs_repository.h index 6ed52f816..23aff2b97 100644 --- a/common/repositories/base/base_character_pet_buffs_repository.h +++ b/common/repositories/base/base_character_pet_buffs_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterPetBuffsRepository { public: struct CharacterPetBuffs { @@ -166,7 +165,7 @@ public: e.counters = static_cast(atoi(row[7])); e.numhits = static_cast(atoi(row[8])); e.rune = static_cast(atoi(row[9])); - e.instrument_mod = static_cast(strtoul(row[10], nullptr, 10)); + e.instrument_mod = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 10; return e; } @@ -326,7 +325,7 @@ public: e.counters = static_cast(atoi(row[7])); e.numhits = static_cast(atoi(row[8])); e.rune = static_cast(atoi(row[9])); - e.instrument_mod = static_cast(strtoul(row[10], nullptr, 10)); + e.instrument_mod = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 10; all_entries.push_back(e); } @@ -361,7 +360,7 @@ public: e.counters = static_cast(atoi(row[7])); e.numhits = static_cast(atoi(row[8])); e.rune = static_cast(atoi(row[9])); - e.instrument_mod = static_cast(strtoul(row[10], nullptr, 10)); + e.instrument_mod = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 10; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_pet_info_repository.h b/common/repositories/base/base_character_pet_info_repository.h index 8d94d2292..973c6d41b 100644 --- a/common/repositories/base/base_character_pet_info_repository.h +++ b/common/repositories/base/base_character_pet_info_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterPetInfoRepository { public: struct CharacterPetInfo { @@ -155,7 +154,7 @@ public: e.spell_id = static_cast(atoi(row[4])); e.hp = static_cast(atoi(row[5])); e.mana = static_cast(atoi(row[6])); - e.size = strtof(row[7], nullptr); + e.size = row[7] ? strtof(row[7], nullptr) : 0; e.taunting = static_cast(atoi(row[8])); return e; @@ -307,7 +306,7 @@ public: e.spell_id = static_cast(atoi(row[4])); e.hp = static_cast(atoi(row[5])); e.mana = static_cast(atoi(row[6])); - e.size = strtof(row[7], nullptr); + e.size = row[7] ? strtof(row[7], nullptr) : 0; e.taunting = static_cast(atoi(row[8])); all_entries.push_back(e); @@ -340,7 +339,7 @@ public: e.spell_id = static_cast(atoi(row[4])); e.hp = static_cast(atoi(row[5])); e.mana = static_cast(atoi(row[6])); - e.size = strtof(row[7], nullptr); + e.size = row[7] ? strtof(row[7], nullptr) : 0; e.taunting = static_cast(atoi(row[8])); all_entries.push_back(e); diff --git a/common/repositories/base/base_character_pet_inventory_repository.h b/common/repositories/base/base_character_pet_inventory_repository.h index 4136711b9..e10164b3a 100644 --- a/common/repositories/base/base_character_pet_inventory_repository.h +++ b/common/repositories/base/base_character_pet_inventory_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterPetInventoryRepository { public: struct CharacterPetInventory { diff --git a/common/repositories/base/base_character_potionbelt_repository.h b/common/repositories/base/base_character_potionbelt_repository.h index 3b28ac8a9..d150c377d 100644 --- a/common/repositories/base/base_character_potionbelt_repository.h +++ b/common/repositories/base/base_character_potionbelt_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterPotionbeltRepository { public: struct CharacterPotionbelt { @@ -128,10 +127,10 @@ public: if (results.RowCount() == 1) { CharacterPotionbelt e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.potion_id = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.icon = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.potion_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.icon = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -260,10 +259,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterPotionbelt e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.potion_id = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.icon = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.potion_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.icon = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -288,10 +287,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterPotionbelt e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.potion_id = static_cast(strtoul(row[1], nullptr, 10)); - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.icon = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.potion_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.icon = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_skills_repository.h b/common/repositories/base/base_character_skills_repository.h index c65822410..6b2f579ab 100644 --- a/common/repositories/base/base_character_skills_repository.h +++ b/common/repositories/base/base_character_skills_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterSkillsRepository { public: struct CharacterSkills { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterSkills e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.skill_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.skill_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -251,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterSkills e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.skill_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.skill_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -278,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterSkills e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.skill_id = static_cast(strtoul(row[1], nullptr, 10)); - e.value = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.skill_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.value = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_spells_repository.h b/common/repositories/base/base_character_spells_repository.h index c02b1290a..7b313644d 100644 --- a/common/repositories/base/base_character_spells_repository.h +++ b/common/repositories/base/base_character_spells_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterSpellsRepository { public: struct CharacterSpells { @@ -124,9 +123,9 @@ public: if (results.RowCount() == 1) { CharacterSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -251,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -278,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_character_stats_record_repository.h b/common/repositories/base/base_character_stats_record_repository.h index a73bcbc2c..657515233 100644 --- a/common/repositories/base/base_character_stats_record_repository.h +++ b/common/repositories/base/base_character_stats_record_repository.h @@ -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_STATS_RECORD_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterStatsRecordRepository { public: struct CharacterStatsRecord { @@ -415,9 +414,9 @@ public: e.class_ = static_cast(atoi(row[4])); e.race = static_cast(atoi(row[5])); e.aa_points = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.endurance = strtoll(row[9], nullptr, 10); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.endurance = row[9] ? strtoll(row[9], nullptr, 10) : 0; e.ac = static_cast(atoi(row[10])); e.strength = static_cast(atoi(row[11])); e.stamina = static_cast(atoi(row[12])); @@ -827,9 +826,9 @@ public: e.class_ = static_cast(atoi(row[4])); e.race = static_cast(atoi(row[5])); e.aa_points = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.endurance = strtoll(row[9], nullptr, 10); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.endurance = row[9] ? strtoll(row[9], nullptr, 10) : 0; e.ac = static_cast(atoi(row[10])); e.strength = static_cast(atoi(row[11])); e.stamina = static_cast(atoi(row[12])); @@ -925,9 +924,9 @@ public: e.class_ = static_cast(atoi(row[4])); e.race = static_cast(atoi(row[5])); e.aa_points = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.endurance = strtoll(row[9], nullptr, 10); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.endurance = row[9] ? strtoll(row[9], nullptr, 10) : 0; e.ac = static_cast(atoi(row[10])); e.strength = static_cast(atoi(row[11])); e.stamina = static_cast(atoi(row[12])); @@ -1050,6 +1049,208 @@ 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 CharacterStatsRecord &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.character_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.aa_points)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.endurance)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.strength)); + v.push_back(std::to_string(e.stamina)); + v.push_back(std::to_string(e.dexterity)); + v.push_back(std::to_string(e.agility)); + v.push_back(std::to_string(e.intelligence)); + v.push_back(std::to_string(e.wisdom)); + v.push_back(std::to_string(e.charisma)); + v.push_back(std::to_string(e.magic_resist)); + v.push_back(std::to_string(e.fire_resist)); + v.push_back(std::to_string(e.cold_resist)); + v.push_back(std::to_string(e.poison_resist)); + v.push_back(std::to_string(e.disease_resist)); + v.push_back(std::to_string(e.corruption_resist)); + v.push_back(std::to_string(e.heroic_strength)); + v.push_back(std::to_string(e.heroic_stamina)); + v.push_back(std::to_string(e.heroic_dexterity)); + v.push_back(std::to_string(e.heroic_agility)); + v.push_back(std::to_string(e.heroic_intelligence)); + v.push_back(std::to_string(e.heroic_wisdom)); + v.push_back(std::to_string(e.heroic_charisma)); + v.push_back(std::to_string(e.heroic_magic_resist)); + v.push_back(std::to_string(e.heroic_fire_resist)); + v.push_back(std::to_string(e.heroic_cold_resist)); + v.push_back(std::to_string(e.heroic_poison_resist)); + v.push_back(std::to_string(e.heroic_disease_resist)); + v.push_back(std::to_string(e.heroic_corruption_resist)); + v.push_back(std::to_string(e.haste)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.clairvoyance)); + v.push_back(std::to_string(e.combat_effects)); + v.push_back(std::to_string(e.damage_shield_mitigation)); + v.push_back(std::to_string(e.damage_shield)); + v.push_back(std::to_string(e.dot_shielding)); + v.push_back(std::to_string(e.hp_regen)); + v.push_back(std::to_string(e.mana_regen)); + v.push_back(std::to_string(e.endurance_regen)); + v.push_back(std::to_string(e.shielding)); + v.push_back(std::to_string(e.spell_damage)); + v.push_back(std::to_string(e.spell_shielding)); + v.push_back(std::to_string(e.strikethrough)); + v.push_back(std::to_string(e.stun_resist)); + v.push_back(std::to_string(e.backstab)); + v.push_back(std::to_string(e.wind)); + v.push_back(std::to_string(e.brass)); + v.push_back(std::to_string(e.string)); + v.push_back(std::to_string(e.percussion)); + v.push_back(std::to_string(e.singing)); + v.push_back(std::to_string(e.baking)); + v.push_back(std::to_string(e.alchemy)); + v.push_back(std::to_string(e.tailoring)); + v.push_back(std::to_string(e.blacksmithing)); + v.push_back(std::to_string(e.fletching)); + v.push_back(std::to_string(e.brewing)); + v.push_back(std::to_string(e.jewelry)); + v.push_back(std::to_string(e.pottery)); + v.push_back(std::to_string(e.research)); + v.push_back(std::to_string(e.alcohol)); + v.push_back(std::to_string(e.fishing)); + v.push_back(std::to_string(e.tinkering)); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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.character_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.aa_points)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.endurance)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.strength)); + v.push_back(std::to_string(e.stamina)); + v.push_back(std::to_string(e.dexterity)); + v.push_back(std::to_string(e.agility)); + v.push_back(std::to_string(e.intelligence)); + v.push_back(std::to_string(e.wisdom)); + v.push_back(std::to_string(e.charisma)); + v.push_back(std::to_string(e.magic_resist)); + v.push_back(std::to_string(e.fire_resist)); + v.push_back(std::to_string(e.cold_resist)); + v.push_back(std::to_string(e.poison_resist)); + v.push_back(std::to_string(e.disease_resist)); + v.push_back(std::to_string(e.corruption_resist)); + v.push_back(std::to_string(e.heroic_strength)); + v.push_back(std::to_string(e.heroic_stamina)); + v.push_back(std::to_string(e.heroic_dexterity)); + v.push_back(std::to_string(e.heroic_agility)); + v.push_back(std::to_string(e.heroic_intelligence)); + v.push_back(std::to_string(e.heroic_wisdom)); + v.push_back(std::to_string(e.heroic_charisma)); + v.push_back(std::to_string(e.heroic_magic_resist)); + v.push_back(std::to_string(e.heroic_fire_resist)); + v.push_back(std::to_string(e.heroic_cold_resist)); + v.push_back(std::to_string(e.heroic_poison_resist)); + v.push_back(std::to_string(e.heroic_disease_resist)); + v.push_back(std::to_string(e.heroic_corruption_resist)); + v.push_back(std::to_string(e.haste)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.clairvoyance)); + v.push_back(std::to_string(e.combat_effects)); + v.push_back(std::to_string(e.damage_shield_mitigation)); + v.push_back(std::to_string(e.damage_shield)); + v.push_back(std::to_string(e.dot_shielding)); + v.push_back(std::to_string(e.hp_regen)); + v.push_back(std::to_string(e.mana_regen)); + v.push_back(std::to_string(e.endurance_regen)); + v.push_back(std::to_string(e.shielding)); + v.push_back(std::to_string(e.spell_damage)); + v.push_back(std::to_string(e.spell_shielding)); + v.push_back(std::to_string(e.strikethrough)); + v.push_back(std::to_string(e.stun_resist)); + v.push_back(std::to_string(e.backstab)); + v.push_back(std::to_string(e.wind)); + v.push_back(std::to_string(e.brass)); + v.push_back(std::to_string(e.string)); + v.push_back(std::to_string(e.percussion)); + v.push_back(std::to_string(e.singing)); + v.push_back(std::to_string(e.baking)); + v.push_back(std::to_string(e.alchemy)); + v.push_back(std::to_string(e.tailoring)); + v.push_back(std::to_string(e.blacksmithing)); + v.push_back(std::to_string(e.fletching)); + v.push_back(std::to_string(e.brewing)); + v.push_back(std::to_string(e.jewelry)); + v.push_back(std::to_string(e.pottery)); + v.push_back(std::to_string(e.research)); + v.push_back(std::to_string(e.alcohol)); + v.push_back(std::to_string(e.fishing)); + v.push_back(std::to_string(e.tinkering)); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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_CHARACTER_STATS_RECORD_REPOSITORY_H diff --git a/common/repositories/base/base_character_task_timers_repository.h b/common/repositories/base/base_character_task_timers_repository.h index 6c9e76b19..d76fadc9b 100644 --- a/common/repositories/base/base_character_task_timers_repository.h +++ b/common/repositories/base/base_character_task_timers_repository.h @@ -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_TASK_TIMERS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_task_timers_id ) ); @@ -134,9 +135,9 @@ public: if (results.RowCount() == 1) { CharacterTaskTimers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.task_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.task_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.timer_type = static_cast(atoi(row[3])); e.timer_group = static_cast(atoi(row[4])); e.expire_time = strtoll(row[5] ? row[5] : "-1", nullptr, 10); @@ -273,9 +274,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterTaskTimers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.task_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.task_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.timer_type = static_cast(atoi(row[3])); e.timer_group = static_cast(atoi(row[4])); e.expire_time = strtoll(row[5] ? row[5] : "-1", nullptr, 10); @@ -303,9 +304,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterTaskTimers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.task_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.task_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.timer_type = static_cast(atoi(row[3])); e.timer_group = static_cast(atoi(row[4])); e.expire_time = strtoll(row[5] ? row[5] : "-1", nullptr, 10); @@ -367,6 +368,72 @@ 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 CharacterTaskTimers &e + ) + { + std::vector 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.task_id)); + v.push_back(std::to_string(e.timer_type)); + v.push_back(std::to_string(e.timer_group)); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + + 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(std::to_string(e.character_id)); + v.push_back(std::to_string(e.task_id)); + v.push_back(std::to_string(e.timer_type)); + v.push_back(std::to_string(e.timer_group)); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + + 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_CHARACTER_TASK_TIMERS_REPOSITORY_H diff --git a/common/repositories/base/base_character_tasks_repository.h b/common/repositories/base/base_character_tasks_repository.h index 070767ff0..d0e38a8d1 100644 --- a/common/repositories/base/base_character_tasks_repository.h +++ b/common/repositories/base/base_character_tasks_repository.h @@ -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_TASKS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), character_tasks_id ) ); @@ -134,11 +135,11 @@ public: if (results.RowCount() == 1) { CharacterTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.slot = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.type = static_cast(atoi(row[3])); - e.acceptedtime = static_cast(strtoul(row[4], nullptr, 10)); + e.acceptedtime = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.was_rewarded = static_cast(atoi(row[5])); return e; @@ -274,11 +275,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.slot = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.type = static_cast(atoi(row[3])); - e.acceptedtime = static_cast(strtoul(row[4], nullptr, 10)); + e.acceptedtime = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.was_rewarded = static_cast(atoi(row[5])); all_entries.push_back(e); @@ -304,11 +305,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CharacterTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); - e.slot = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.type = static_cast(atoi(row[3])); - e.acceptedtime = static_cast(strtoul(row[4], nullptr, 10)); + e.acceptedtime = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.was_rewarded = static_cast(atoi(row[5])); all_entries.push_back(e); @@ -368,6 +369,72 @@ 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 CharacterTasks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.acceptedtime)); + v.push_back(std::to_string(e.was_rewarded)); + + 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.charid)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.acceptedtime)); + v.push_back(std::to_string(e.was_rewarded)); + + 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_CHARACTER_TASKS_REPOSITORY_H diff --git a/common/repositories/base/base_character_tribute_repository.h b/common/repositories/base/base_character_tribute_repository.h index 9b040f7fd..70d315b31 100644 --- a/common/repositories/base/base_character_tribute_repository.h +++ b/common/repositories/base/base_character_tribute_repository.h @@ -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_TRIBUTE_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCharacterTributeRepository { public: struct CharacterTribute { @@ -129,9 +128,9 @@ public: CharacterTribute e{}; e.id = static_cast(atoi(row[0])); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.tier = static_cast(strtoul(row[2], nullptr, 10)); - e.tribute = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.tier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -260,9 +259,9 @@ public: CharacterTribute e{}; e.id = static_cast(atoi(row[0])); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.tier = static_cast(strtoul(row[2], nullptr, 10)); - e.tribute = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.tier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -288,9 +287,9 @@ public: CharacterTribute e{}; e.id = static_cast(atoi(row[0])); - e.character_id = static_cast(strtoul(row[1], nullptr, 10)); - e.tier = static_cast(strtoul(row[2], nullptr, 10)); - e.tribute = static_cast(strtoul(row[3], nullptr, 10)); + e.character_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.tier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -349,6 +348,68 @@ 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 CharacterTribute &e + ) + { + std::vector 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.tier)); + v.push_back(std::to_string(e.tribute)); + + 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(std::to_string(e.character_id)); + v.push_back(std::to_string(e.tier)); + v.push_back(std::to_string(e.tribute)); + + 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_CHARACTER_TRIBUTE_REPOSITORY_H diff --git a/common/repositories/base/base_chatchannel_reserved_names_repository.h b/common/repositories/base/base_chatchannel_reserved_names_repository.h index df5cb9241..04474ec78 100644 --- a/common/repositories/base/base_chatchannel_reserved_names_repository.h +++ b/common/repositories/base/base_chatchannel_reserved_names_repository.h @@ -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_CHATCHANNEL_RESERVED_NAMES_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseChatchannelReservedNamesRepository { public: struct ChatchannelReservedNames { @@ -329,6 +328,64 @@ 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 ChatchannelReservedNames &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.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 &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.name) + "'"); + + 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_CHATCHANNEL_RESERVED_NAMES_REPOSITORY_H diff --git a/common/repositories/base/base_chatchannels_repository.h b/common/repositories/base/base_chatchannels_repository.h index a767d589a..035155d23 100644 --- a/common/repositories/base/base_chatchannels_repository.h +++ b/common/repositories/base/base_chatchannels_repository.h @@ -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_CHATCHANNELS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseChatchannelsRepository { public: struct Chatchannels { @@ -359,6 +358,70 @@ 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 Chatchannels &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.owner) + "'"); + v.push_back("'" + Strings::Escape(e.password) + "'"); + v.push_back(std::to_string(e.minstatus)); + + 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.name) + "'"); + v.push_back("'" + Strings::Escape(e.owner) + "'"); + v.push_back("'" + Strings::Escape(e.password) + "'"); + v.push_back(std::to_string(e.minstatus)); + + 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_CHATCHANNELS_REPOSITORY_H diff --git a/common/repositories/base/base_command_subsettings_repository.h b/common/repositories/base/base_command_subsettings_repository.h index 1731f5470..d12bf2250 100644 --- a/common/repositories/base/base_command_subsettings_repository.h +++ b/common/repositories/base/base_command_subsettings_repository.h @@ -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_COMMAND_SUBSETTINGS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseCommandSubsettingsRepository { public: struct CommandSubsettings { @@ -132,10 +131,10 @@ public: if (results.RowCount() == 1) { CommandSubsettings e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.parent_command = row[1] ? row[1] : ""; e.sub_command = row[2] ? row[2] : ""; - e.access_level = static_cast(strtoul(row[3], nullptr, 10)); + e.access_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.top_level_aliases = row[4] ? row[4] : ""; return e; @@ -267,10 +266,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CommandSubsettings e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.parent_command = row[1] ? row[1] : ""; e.sub_command = row[2] ? row[2] : ""; - e.access_level = static_cast(strtoul(row[3], nullptr, 10)); + e.access_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.top_level_aliases = row[4] ? row[4] : ""; all_entries.push_back(e); @@ -296,10 +295,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CommandSubsettings e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.parent_command = row[1] ? row[1] : ""; e.sub_command = row[2] ? row[2] : ""; - e.access_level = static_cast(strtoul(row[3], nullptr, 10)); + e.access_level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.top_level_aliases = row[4] ? row[4] : ""; all_entries.push_back(e); @@ -359,6 +358,70 @@ 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 CommandSubsettings &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.parent_command) + "'"); + v.push_back("'" + Strings::Escape(e.sub_command) + "'"); + v.push_back(std::to_string(e.access_level)); + v.push_back("'" + Strings::Escape(e.top_level_aliases) + "'"); + + 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.parent_command) + "'"); + v.push_back("'" + Strings::Escape(e.sub_command) + "'"); + v.push_back(std::to_string(e.access_level)); + v.push_back("'" + Strings::Escape(e.top_level_aliases) + "'"); + + 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_COMMAND_SUBSETTINGS_REPOSITORY_H diff --git a/common/repositories/base/base_completed_shared_task_activity_state_repository.h b/common/repositories/base/base_completed_shared_task_activity_state_repository.h index e2225e8ea..36d4223df 100644 --- a/common/repositories/base/base_completed_shared_task_activity_state_repository.h +++ b/common/repositories/base/base_completed_shared_task_activity_state_repository.h @@ -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_COMPLETED_SHARED_TASK_ACTIVITY_STATE_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), completed_shared_task_activity_state_id ) ); @@ -130,7 +131,7 @@ public: if (results.RowCount() == 1) { CompletedSharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -266,7 +267,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -295,7 +296,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -358,6 +359,70 @@ 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 CompletedSharedTaskActivityState &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.shared_task_id)); + v.push_back(std::to_string(e.activity_id)); + v.push_back(std::to_string(e.done_count)); + v.push_back("FROM_UNIXTIME(" + (e.updated_time > 0 ? std::to_string(e.updated_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completed_time > 0 ? std::to_string(e.completed_time) : "null") + ")"); + + 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.shared_task_id)); + v.push_back(std::to_string(e.activity_id)); + v.push_back(std::to_string(e.done_count)); + v.push_back("FROM_UNIXTIME(" + (e.updated_time > 0 ? std::to_string(e.updated_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completed_time > 0 ? std::to_string(e.completed_time) : "null") + ")"); + + 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_COMPLETED_SHARED_TASK_ACTIVITY_STATE_REPOSITORY_H diff --git a/common/repositories/base/base_completed_shared_task_members_repository.h b/common/repositories/base/base_completed_shared_task_members_repository.h index a58dc0f00..80e4fbdab 100644 --- a/common/repositories/base/base_completed_shared_task_members_repository.h +++ b/common/repositories/base/base_completed_shared_task_members_repository.h @@ -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_COMPLETED_SHARED_TASK_MEMBERS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), completed_shared_task_members_id ) ); @@ -122,8 +123,8 @@ public: if (results.RowCount() == 1) { CompletedSharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); return e; @@ -250,8 +251,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -277,8 +278,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -338,6 +339,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 CompletedSharedTaskMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.shared_task_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.is_leader)); + + 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.shared_task_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.is_leader)); + + 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_COMPLETED_SHARED_TASK_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_completed_shared_tasks_repository.h b/common/repositories/base/base_completed_shared_tasks_repository.h index 6ba398908..8327b5ec8 100644 --- a/common/repositories/base/base_completed_shared_tasks_repository.h +++ b/common/repositories/base/base_completed_shared_tasks_repository.h @@ -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_COMPLETED_SHARED_TASKS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), completed_shared_tasks_id ) ); @@ -134,7 +135,7 @@ public: if (results.RowCount() == 1) { CompletedSharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -274,7 +275,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -304,7 +305,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedSharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -368,6 +369,72 @@ 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 CompletedSharedTasks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.task_id)); + v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")"); + v.push_back(std::to_string(e.is_locked)); + + 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(std::to_string(e.task_id)); + v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")"); + v.push_back(std::to_string(e.is_locked)); + + 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_COMPLETED_SHARED_TASKS_REPOSITORY_H diff --git a/common/repositories/base/base_completed_tasks_repository.h b/common/repositories/base/base_completed_tasks_repository.h index e195da188..4adf2a838 100644 --- a/common/repositories/base/base_completed_tasks_repository.h +++ b/common/repositories/base/base_completed_tasks_repository.h @@ -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_COMPLETED_TASKS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), completed_tasks_id ) ); @@ -126,9 +127,9 @@ public: if (results.RowCount() == 1) { CompletedTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.completedtime = static_cast(strtoul(row[1], nullptr, 10)); - e.taskid = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.completedtime = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.taskid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.activityid = static_cast(atoi(row[3])); return e; @@ -258,9 +259,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.completedtime = static_cast(strtoul(row[1], nullptr, 10)); - e.taskid = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.completedtime = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.taskid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.activityid = static_cast(atoi(row[3])); all_entries.push_back(e); @@ -286,9 +287,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { CompletedTasks e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.completedtime = static_cast(strtoul(row[1], nullptr, 10)); - e.taskid = static_cast(strtoul(row[2], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.completedtime = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.taskid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.activityid = static_cast(atoi(row[3])); all_entries.push_back(e); @@ -348,6 +349,68 @@ 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 CompletedTasks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.completedtime)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.activityid)); + + 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.charid)); + v.push_back(std::to_string(e.completedtime)); + v.push_back(std::to_string(e.taskid)); + v.push_back(std::to_string(e.activityid)); + + 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_COMPLETED_TASKS_REPOSITORY_H diff --git a/common/repositories/base/base_content_flags_repository.h b/common/repositories/base/base_content_flags_repository.h index f8e2bc4dc..fa3ee3094 100644 --- a/common/repositories/base/base_content_flags_repository.h +++ b/common/repositories/base/base_content_flags_repository.h @@ -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_CONTENT_FLAGS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), content_flags_id ) ); @@ -347,6 +348,68 @@ 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 ContentFlags &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.flag_name) + "'"); + v.push_back(std::to_string(e.enabled)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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.flag_name) + "'"); + v.push_back(std::to_string(e.enabled)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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_CONTENT_FLAGS_REPOSITORY_H diff --git a/common/repositories/base/base_damageshieldtypes_repository.h b/common/repositories/base/base_damageshieldtypes_repository.h index cc1ec4b8f..775c7c6f8 100644 --- a/common/repositories/base/base_damageshieldtypes_repository.h +++ b/common/repositories/base/base_damageshieldtypes_repository.h @@ -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_DAMAGESHIELDTYPES_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), damageshieldtypes_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { Damageshieldtypes e{}; - e.spellid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Damageshieldtypes e{}; - e.spellid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Damageshieldtypes e{}; - e.spellid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.spellid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 Damageshieldtypes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + + 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.spellid)); + v.push_back(std::to_string(e.type)); + + 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_DAMAGESHIELDTYPES_REPOSITORY_H diff --git a/common/repositories/base/base_data_buckets_repository.h b/common/repositories/base/base_data_buckets_repository.h index 94a08fce4..3e7ca05d0 100644 --- a/common/repositories/base/base_data_buckets_repository.h +++ b/common/repositories/base/base_data_buckets_repository.h @@ -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_DATA_BUCKETS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include #include - class BaseDataBucketsRepository { public: struct DataBuckets { @@ -155,13 +154,13 @@ public: if (results.RowCount() == 1) { DataBuckets e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; - e.expires = static_cast(strtoul(row[3], nullptr, 10)); - e.character_id = strtoll(row[4], nullptr, 10); - e.npc_id = strtoll(row[5], nullptr, 10); - e.bot_id = strtoll(row[6], nullptr, 10); + e.expires = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.character_id = row[4] ? strtoll(row[4], nullptr, 10) : 0; + e.npc_id = row[5] ? strtoll(row[5], nullptr, 10) : 0; + e.bot_id = row[6] ? strtoll(row[6], nullptr, 10) : 0; return e; } @@ -298,13 +297,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DataBuckets e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; - e.expires = static_cast(strtoul(row[3], nullptr, 10)); - e.character_id = strtoll(row[4], nullptr, 10); - e.npc_id = strtoll(row[5], nullptr, 10); - e.bot_id = strtoll(row[6], nullptr, 10); + e.expires = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.character_id = row[4] ? strtoll(row[4], nullptr, 10) : 0; + e.npc_id = row[5] ? strtoll(row[5], nullptr, 10) : 0; + e.bot_id = row[6] ? strtoll(row[6], nullptr, 10) : 0; all_entries.push_back(e); } @@ -329,13 +328,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DataBuckets e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; - e.expires = static_cast(strtoul(row[3], nullptr, 10)); - e.character_id = strtoll(row[4], nullptr, 10); - e.npc_id = strtoll(row[5], nullptr, 10); - e.bot_id = strtoll(row[6], nullptr, 10); + e.expires = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.character_id = row[4] ? strtoll(row[4], nullptr, 10) : 0; + e.npc_id = row[5] ? strtoll(row[5], nullptr, 10) : 0; + e.bot_id = row[6] ? strtoll(row[6], nullptr, 10) : 0; all_entries.push_back(e); } @@ -394,6 +393,74 @@ 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 DataBuckets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.key_) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back(std::to_string(e.expires)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.npc_id)); + v.push_back(std::to_string(e.bot_id)); + + 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.key_) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back(std::to_string(e.expires)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.npc_id)); + v.push_back(std::to_string(e.bot_id)); + + 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_DATA_BUCKETS_REPOSITORY_H diff --git a/common/repositories/base/base_db_str_repository.h b/common/repositories/base/base_db_str_repository.h index d79d65410..ad1ef0e2e 100644 --- a/common/repositories/base/base_db_str_repository.h +++ b/common/repositories/base/base_db_str_repository.h @@ -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_DB_STR_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), db_str_id ) ); @@ -338,6 +339,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 DbStr &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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_DB_STR_REPOSITORY_H diff --git a/common/repositories/base/base_discord_webhooks_repository.h b/common/repositories/base/base_discord_webhooks_repository.h index 6967c1c28..b4ed89083 100644 --- a/common/repositories/base/base_discord_webhooks_repository.h +++ b/common/repositories/base/base_discord_webhooks_repository.h @@ -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_DISCORD_WEBHOOKS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), discord_webhooks_id ) ); @@ -357,6 +358,70 @@ 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 DiscordWebhooks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.webhook_name) + "'"); + v.push_back("'" + Strings::Escape(e.webhook_url) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.deleted_at > 0 ? std::to_string(e.deleted_at) : "null") + ")"); + + 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.webhook_name) + "'"); + v.push_back("'" + Strings::Escape(e.webhook_url) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.deleted_at > 0 ? std::to_string(e.deleted_at) : "null") + ")"); + + 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_DISCORD_WEBHOOKS_REPOSITORY_H diff --git a/common/repositories/base/base_discovered_items_repository.h b/common/repositories/base/base_discovered_items_repository.h index 5cef65213..c6f494c1b 100644 --- a/common/repositories/base/base_discovered_items_repository.h +++ b/common/repositories/base/base_discovered_items_repository.h @@ -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_DISCOVERED_ITEMS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), discovered_items_id ) ); @@ -126,9 +127,9 @@ public: if (results.RowCount() == 1) { DiscoveredItems e{}; - e.item_id = static_cast(strtoul(row[0], nullptr, 10)); + e.item_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.char_name = row[1] ? row[1] : ""; - e.discovered_date = static_cast(strtoul(row[2], nullptr, 10)); + e.discovered_date = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.account_status = static_cast(atoi(row[3])); return e; @@ -258,9 +259,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DiscoveredItems e{}; - e.item_id = static_cast(strtoul(row[0], nullptr, 10)); + e.item_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.char_name = row[1] ? row[1] : ""; - e.discovered_date = static_cast(strtoul(row[2], nullptr, 10)); + e.discovered_date = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.account_status = static_cast(atoi(row[3])); all_entries.push_back(e); @@ -286,9 +287,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DiscoveredItems e{}; - e.item_id = static_cast(strtoul(row[0], nullptr, 10)); + e.item_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.char_name = row[1] ? row[1] : ""; - e.discovered_date = static_cast(strtoul(row[2], nullptr, 10)); + e.discovered_date = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.account_status = static_cast(atoi(row[3])); all_entries.push_back(e); @@ -348,6 +349,68 @@ 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 DiscoveredItems &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.item_id)); + v.push_back("'" + Strings::Escape(e.char_name) + "'"); + v.push_back(std::to_string(e.discovered_date)); + v.push_back(std::to_string(e.account_status)); + + 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.item_id)); + v.push_back("'" + Strings::Escape(e.char_name) + "'"); + v.push_back(std::to_string(e.discovered_date)); + v.push_back(std::to_string(e.account_status)); + + 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_DISCOVERED_ITEMS_REPOSITORY_H diff --git a/common/repositories/base/base_doors_repository.h b/common/repositories/base/base_doors_repository.h index 3711f192c..fde8aefaf 100644 --- a/common/repositories/base/base_doors_repository.h +++ b/common/repositories/base/base_doors_repository.h @@ -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_DOORS_REPOSITORY_H @@ -244,8 +244,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), doors_id ) ); @@ -259,31 +260,31 @@ public: e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); e.name = row[4] ? row[4] : ""; - e.pos_y = strtof(row[5], nullptr); - e.pos_x = strtof(row[6], nullptr); - e.pos_z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.pos_y = row[5] ? strtof(row[5], nullptr) : 0; + e.pos_x = row[6] ? strtof(row[6], nullptr) : 0; + e.pos_z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.opentype = static_cast(atoi(row[9])); e.guild = static_cast(atoi(row[10])); e.lockpick = static_cast(atoi(row[11])); e.keyitem = static_cast(atoi(row[12])); - e.nokeyring = static_cast(strtoul(row[13], nullptr, 10)); + e.nokeyring = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.triggerdoor = static_cast(atoi(row[14])); e.triggertype = static_cast(atoi(row[15])); e.disable_timer = static_cast(atoi(row[16])); e.doorisopen = static_cast(atoi(row[17])); e.door_param = static_cast(atoi(row[18])); e.dest_zone = row[19] ? row[19] : ""; - e.dest_instance = static_cast(strtoul(row[20], nullptr, 10)); - e.dest_x = strtof(row[21], nullptr); - e.dest_y = strtof(row[22], nullptr); - e.dest_z = strtof(row[23], nullptr); - e.dest_heading = strtof(row[24], nullptr); + e.dest_instance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.dest_x = row[21] ? strtof(row[21], nullptr) : 0; + e.dest_y = row[22] ? strtof(row[22], nullptr) : 0; + e.dest_z = row[23] ? strtof(row[23], nullptr) : 0; + e.dest_heading = row[24] ? strtof(row[24], nullptr) : 0; e.invert_state = static_cast(atoi(row[25])); e.incline = static_cast(atoi(row[26])); - e.size = static_cast(strtoul(row[27], nullptr, 10)); - e.buffer = strtof(row[28], nullptr); - e.client_version_mask = static_cast(strtoul(row[29], nullptr, 10)); + e.size = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 100; + e.buffer = row[28] ? strtof(row[28], nullptr) : 0; + e.client_version_mask = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 4294967295; e.is_ldon_door = static_cast(atoi(row[30])); e.dz_switch_id = static_cast(atoi(row[31])); e.min_expansion = static_cast(atoi(row[32])); @@ -518,31 +519,31 @@ public: e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); e.name = row[4] ? row[4] : ""; - e.pos_y = strtof(row[5], nullptr); - e.pos_x = strtof(row[6], nullptr); - e.pos_z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.pos_y = row[5] ? strtof(row[5], nullptr) : 0; + e.pos_x = row[6] ? strtof(row[6], nullptr) : 0; + e.pos_z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.opentype = static_cast(atoi(row[9])); e.guild = static_cast(atoi(row[10])); e.lockpick = static_cast(atoi(row[11])); e.keyitem = static_cast(atoi(row[12])); - e.nokeyring = static_cast(strtoul(row[13], nullptr, 10)); + e.nokeyring = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.triggerdoor = static_cast(atoi(row[14])); e.triggertype = static_cast(atoi(row[15])); e.disable_timer = static_cast(atoi(row[16])); e.doorisopen = static_cast(atoi(row[17])); e.door_param = static_cast(atoi(row[18])); e.dest_zone = row[19] ? row[19] : ""; - e.dest_instance = static_cast(strtoul(row[20], nullptr, 10)); - e.dest_x = strtof(row[21], nullptr); - e.dest_y = strtof(row[22], nullptr); - e.dest_z = strtof(row[23], nullptr); - e.dest_heading = strtof(row[24], nullptr); + e.dest_instance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.dest_x = row[21] ? strtof(row[21], nullptr) : 0; + e.dest_y = row[22] ? strtof(row[22], nullptr) : 0; + e.dest_z = row[23] ? strtof(row[23], nullptr) : 0; + e.dest_heading = row[24] ? strtof(row[24], nullptr) : 0; e.invert_state = static_cast(atoi(row[25])); e.incline = static_cast(atoi(row[26])); - e.size = static_cast(strtoul(row[27], nullptr, 10)); - e.buffer = strtof(row[28], nullptr); - e.client_version_mask = static_cast(strtoul(row[29], nullptr, 10)); + e.size = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 100; + e.buffer = row[28] ? strtof(row[28], nullptr) : 0; + e.client_version_mask = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 4294967295; e.is_ldon_door = static_cast(atoi(row[30])); e.dz_switch_id = static_cast(atoi(row[31])); e.min_expansion = static_cast(atoi(row[32])); @@ -578,31 +579,31 @@ public: e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); e.name = row[4] ? row[4] : ""; - e.pos_y = strtof(row[5], nullptr); - e.pos_x = strtof(row[6], nullptr); - e.pos_z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.pos_y = row[5] ? strtof(row[5], nullptr) : 0; + e.pos_x = row[6] ? strtof(row[6], nullptr) : 0; + e.pos_z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.opentype = static_cast(atoi(row[9])); e.guild = static_cast(atoi(row[10])); e.lockpick = static_cast(atoi(row[11])); e.keyitem = static_cast(atoi(row[12])); - e.nokeyring = static_cast(strtoul(row[13], nullptr, 10)); + e.nokeyring = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; e.triggerdoor = static_cast(atoi(row[14])); e.triggertype = static_cast(atoi(row[15])); e.disable_timer = static_cast(atoi(row[16])); e.doorisopen = static_cast(atoi(row[17])); e.door_param = static_cast(atoi(row[18])); e.dest_zone = row[19] ? row[19] : ""; - e.dest_instance = static_cast(strtoul(row[20], nullptr, 10)); - e.dest_x = strtof(row[21], nullptr); - e.dest_y = strtof(row[22], nullptr); - e.dest_z = strtof(row[23], nullptr); - e.dest_heading = strtof(row[24], nullptr); + e.dest_instance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.dest_x = row[21] ? strtof(row[21], nullptr) : 0; + e.dest_y = row[22] ? strtof(row[22], nullptr) : 0; + e.dest_z = row[23] ? strtof(row[23], nullptr) : 0; + e.dest_heading = row[24] ? strtof(row[24], nullptr) : 0; e.invert_state = static_cast(atoi(row[25])); e.incline = static_cast(atoi(row[26])); - e.size = static_cast(strtoul(row[27], nullptr, 10)); - e.buffer = strtof(row[28], nullptr); - e.client_version_mask = static_cast(strtoul(row[29], nullptr, 10)); + e.size = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 100; + e.buffer = row[28] ? strtof(row[28], nullptr) : 0; + e.client_version_mask = row[29] ? static_cast(strtoul(row[29], nullptr, 10)) : 4294967295; e.is_ldon_door = static_cast(atoi(row[30])); e.dz_switch_id = static_cast(atoi(row[31])); e.min_expansion = static_cast(atoi(row[32])); @@ -667,6 +668,132 @@ 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 Doors &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.doorid)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.pos_y)); + v.push_back(std::to_string(e.pos_x)); + v.push_back(std::to_string(e.pos_z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.opentype)); + v.push_back(std::to_string(e.guild)); + v.push_back(std::to_string(e.lockpick)); + v.push_back(std::to_string(e.keyitem)); + v.push_back(std::to_string(e.nokeyring)); + v.push_back(std::to_string(e.triggerdoor)); + v.push_back(std::to_string(e.triggertype)); + v.push_back(std::to_string(e.disable_timer)); + v.push_back(std::to_string(e.doorisopen)); + v.push_back(std::to_string(e.door_param)); + v.push_back("'" + Strings::Escape(e.dest_zone) + "'"); + v.push_back(std::to_string(e.dest_instance)); + v.push_back(std::to_string(e.dest_x)); + v.push_back(std::to_string(e.dest_y)); + v.push_back(std::to_string(e.dest_z)); + v.push_back(std::to_string(e.dest_heading)); + v.push_back(std::to_string(e.invert_state)); + v.push_back(std::to_string(e.incline)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.buffer)); + v.push_back(std::to_string(e.client_version_mask)); + v.push_back(std::to_string(e.is_ldon_door)); + v.push_back(std::to_string(e.dz_switch_id)); + 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) + "'"); + + 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(std::to_string(e.doorid)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.pos_y)); + v.push_back(std::to_string(e.pos_x)); + v.push_back(std::to_string(e.pos_z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.opentype)); + v.push_back(std::to_string(e.guild)); + v.push_back(std::to_string(e.lockpick)); + v.push_back(std::to_string(e.keyitem)); + v.push_back(std::to_string(e.nokeyring)); + v.push_back(std::to_string(e.triggerdoor)); + v.push_back(std::to_string(e.triggertype)); + v.push_back(std::to_string(e.disable_timer)); + v.push_back(std::to_string(e.doorisopen)); + v.push_back(std::to_string(e.door_param)); + v.push_back("'" + Strings::Escape(e.dest_zone) + "'"); + v.push_back(std::to_string(e.dest_instance)); + v.push_back(std::to_string(e.dest_x)); + v.push_back(std::to_string(e.dest_y)); + v.push_back(std::to_string(e.dest_z)); + v.push_back(std::to_string(e.dest_heading)); + v.push_back(std::to_string(e.invert_state)); + v.push_back(std::to_string(e.incline)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.buffer)); + v.push_back(std::to_string(e.client_version_mask)); + v.push_back(std::to_string(e.is_ldon_door)); + v.push_back(std::to_string(e.dz_switch_id)); + 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) + "'"); + + 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_DOORS_REPOSITORY_H diff --git a/common/repositories/base/base_dynamic_zone_members_repository.h b/common/repositories/base/base_dynamic_zone_members_repository.h index 7cd4fa68f..807300378 100644 --- a/common/repositories/base/base_dynamic_zone_members_repository.h +++ b/common/repositories/base/base_dynamic_zone_members_repository.h @@ -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_DYNAMIC_ZONE_MEMBERS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), dynamic_zone_members_id ) ); @@ -122,9 +123,9 @@ public: if (results.RowCount() == 1) { DynamicZoneMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.character_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.character_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -249,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZoneMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.character_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.character_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -276,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZoneMembers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.character_id = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.character_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -337,6 +338,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 DynamicZoneMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.dynamic_zone_id)); + v.push_back(std::to_string(e.character_id)); + + 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(std::to_string(e.dynamic_zone_id)); + v.push_back(std::to_string(e.character_id)); + + 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_DYNAMIC_ZONE_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_dynamic_zone_templates_repository.h b/common/repositories/base/base_dynamic_zone_templates_repository.h index 40fa29397..b72720b65 100644 --- a/common/repositories/base/base_dynamic_zone_templates_repository.h +++ b/common/repositories/base/base_dynamic_zone_templates_repository.h @@ -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_DYNAMIC_ZONE_TEMPLATES_REPOSITORY_H @@ -188,8 +188,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), dynamic_zone_templates_id ) ); @@ -198,7 +199,7 @@ public: if (results.RowCount() == 1) { DynamicZoneTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[1])); e.zone_version = static_cast(atoi(row[2])); e.name = row[3] ? row[3] : ""; @@ -207,19 +208,19 @@ public: e.duration_seconds = static_cast(atoi(row[6])); e.dz_switch_id = static_cast(atoi(row[7])); e.compass_zone_id = static_cast(atoi(row[8])); - e.compass_x = strtof(row[9], nullptr); - e.compass_y = strtof(row[10], nullptr); - e.compass_z = strtof(row[11], nullptr); + e.compass_x = row[9] ? strtof(row[9], nullptr) : 0; + e.compass_y = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_z = row[11] ? strtof(row[11], nullptr) : 0; e.return_zone_id = static_cast(atoi(row[12])); - e.return_x = strtof(row[13], nullptr); - e.return_y = strtof(row[14], nullptr); - e.return_z = strtof(row[15], nullptr); - e.return_h = strtof(row[16], nullptr); + e.return_x = row[13] ? strtof(row[13], nullptr) : 0; + e.return_y = row[14] ? strtof(row[14], nullptr) : 0; + e.return_z = row[15] ? strtof(row[15], nullptr) : 0; + e.return_h = row[16] ? strtof(row[16], nullptr) : 0; e.override_zone_in = static_cast(atoi(row[17])); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_h = strtof(row[21], nullptr); + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_h = row[21] ? strtof(row[21], nullptr) : 0; return e; } @@ -401,7 +402,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZoneTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[1])); e.zone_version = static_cast(atoi(row[2])); e.name = row[3] ? row[3] : ""; @@ -410,19 +411,19 @@ public: e.duration_seconds = static_cast(atoi(row[6])); e.dz_switch_id = static_cast(atoi(row[7])); e.compass_zone_id = static_cast(atoi(row[8])); - e.compass_x = strtof(row[9], nullptr); - e.compass_y = strtof(row[10], nullptr); - e.compass_z = strtof(row[11], nullptr); + e.compass_x = row[9] ? strtof(row[9], nullptr) : 0; + e.compass_y = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_z = row[11] ? strtof(row[11], nullptr) : 0; e.return_zone_id = static_cast(atoi(row[12])); - e.return_x = strtof(row[13], nullptr); - e.return_y = strtof(row[14], nullptr); - e.return_z = strtof(row[15], nullptr); - e.return_h = strtof(row[16], nullptr); + e.return_x = row[13] ? strtof(row[13], nullptr) : 0; + e.return_y = row[14] ? strtof(row[14], nullptr) : 0; + e.return_z = row[15] ? strtof(row[15], nullptr) : 0; + e.return_h = row[16] ? strtof(row[16], nullptr) : 0; e.override_zone_in = static_cast(atoi(row[17])); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_h = strtof(row[21], nullptr); + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_h = row[21] ? strtof(row[21], nullptr) : 0; all_entries.push_back(e); } @@ -447,7 +448,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZoneTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[1])); e.zone_version = static_cast(atoi(row[2])); e.name = row[3] ? row[3] : ""; @@ -456,19 +457,19 @@ public: e.duration_seconds = static_cast(atoi(row[6])); e.dz_switch_id = static_cast(atoi(row[7])); e.compass_zone_id = static_cast(atoi(row[8])); - e.compass_x = strtof(row[9], nullptr); - e.compass_y = strtof(row[10], nullptr); - e.compass_z = strtof(row[11], nullptr); + e.compass_x = row[9] ? strtof(row[9], nullptr) : 0; + e.compass_y = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_z = row[11] ? strtof(row[11], nullptr) : 0; e.return_zone_id = static_cast(atoi(row[12])); - e.return_x = strtof(row[13], nullptr); - e.return_y = strtof(row[14], nullptr); - e.return_z = strtof(row[15], nullptr); - e.return_h = strtof(row[16], nullptr); + e.return_x = row[13] ? strtof(row[13], nullptr) : 0; + e.return_y = row[14] ? strtof(row[14], nullptr) : 0; + e.return_z = row[15] ? strtof(row[15], nullptr) : 0; + e.return_h = row[16] ? strtof(row[16], nullptr) : 0; e.override_zone_in = static_cast(atoi(row[17])); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_h = strtof(row[21], nullptr); + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_h = row[21] ? strtof(row[21], nullptr) : 0; all_entries.push_back(e); } @@ -527,6 +528,104 @@ 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 DynamicZoneTemplates &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.zone_version)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.min_players)); + v.push_back(std::to_string(e.max_players)); + v.push_back(std::to_string(e.duration_seconds)); + v.push_back(std::to_string(e.dz_switch_id)); + v.push_back(std::to_string(e.compass_zone_id)); + v.push_back(std::to_string(e.compass_x)); + v.push_back(std::to_string(e.compass_y)); + v.push_back(std::to_string(e.compass_z)); + v.push_back(std::to_string(e.return_zone_id)); + v.push_back(std::to_string(e.return_x)); + v.push_back(std::to_string(e.return_y)); + v.push_back(std::to_string(e.return_z)); + v.push_back(std::to_string(e.return_h)); + v.push_back(std::to_string(e.override_zone_in)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_z)); + v.push_back(std::to_string(e.zone_in_h)); + + 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(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.zone_version)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.min_players)); + v.push_back(std::to_string(e.max_players)); + v.push_back(std::to_string(e.duration_seconds)); + v.push_back(std::to_string(e.dz_switch_id)); + v.push_back(std::to_string(e.compass_zone_id)); + v.push_back(std::to_string(e.compass_x)); + v.push_back(std::to_string(e.compass_y)); + v.push_back(std::to_string(e.compass_z)); + v.push_back(std::to_string(e.return_zone_id)); + v.push_back(std::to_string(e.return_x)); + v.push_back(std::to_string(e.return_y)); + v.push_back(std::to_string(e.return_z)); + v.push_back(std::to_string(e.return_h)); + v.push_back(std::to_string(e.override_zone_in)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_z)); + v.push_back(std::to_string(e.zone_in_h)); + + 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_DYNAMIC_ZONE_TEMPLATES_REPOSITORY_H diff --git a/common/repositories/base/base_dynamic_zones_repository.h b/common/repositories/base/base_dynamic_zones_repository.h index 0def54ea1..0ae38786e 100644 --- a/common/repositories/base/base_dynamic_zones_repository.h +++ b/common/repositories/base/base_dynamic_zones_repository.h @@ -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_DYNAMIC_ZONES_REPOSITORY_H @@ -192,8 +192,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), dynamic_zones_id ) ); @@ -202,29 +203,29 @@ public: if (results.RowCount() == 1) { DynamicZones e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[1])); - e.type = static_cast(strtoul(row[2], nullptr, 10)); + e.type = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.uuid = row[3] ? row[3] : ""; e.name = row[4] ? row[4] : ""; - e.leader_id = static_cast(strtoul(row[5], nullptr, 10)); - e.min_players = static_cast(strtoul(row[6], nullptr, 10)); - e.max_players = static_cast(strtoul(row[7], nullptr, 10)); + e.leader_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.min_players = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.max_players = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.dz_switch_id = static_cast(atoi(row[8])); - e.compass_zone_id = static_cast(strtoul(row[9], nullptr, 10)); - e.compass_x = strtof(row[10], nullptr); - e.compass_y = strtof(row[11], nullptr); - e.compass_z = strtof(row[12], nullptr); - e.safe_return_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.safe_return_x = strtof(row[14], nullptr); - e.safe_return_y = strtof(row[15], nullptr); - e.safe_return_z = strtof(row[16], nullptr); - e.safe_return_heading = strtof(row[17], nullptr); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_heading = strtof(row[21], nullptr); - e.has_zone_in = static_cast(strtoul(row[22], nullptr, 10)); + e.compass_zone_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.compass_x = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_y = row[11] ? strtof(row[11], nullptr) : 0; + e.compass_z = row[12] ? strtof(row[12], nullptr) : 0; + e.safe_return_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.safe_return_x = row[14] ? strtof(row[14], nullptr) : 0; + e.safe_return_y = row[15] ? strtof(row[15], nullptr) : 0; + e.safe_return_z = row[16] ? strtof(row[16], nullptr) : 0; + e.safe_return_heading = row[17] ? strtof(row[17], nullptr) : 0; + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_heading = row[21] ? strtof(row[21], nullptr) : 0; + e.has_zone_in = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; return e; } @@ -409,29 +410,29 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZones e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[1])); - e.type = static_cast(strtoul(row[2], nullptr, 10)); + e.type = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.uuid = row[3] ? row[3] : ""; e.name = row[4] ? row[4] : ""; - e.leader_id = static_cast(strtoul(row[5], nullptr, 10)); - e.min_players = static_cast(strtoul(row[6], nullptr, 10)); - e.max_players = static_cast(strtoul(row[7], nullptr, 10)); + e.leader_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.min_players = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.max_players = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.dz_switch_id = static_cast(atoi(row[8])); - e.compass_zone_id = static_cast(strtoul(row[9], nullptr, 10)); - e.compass_x = strtof(row[10], nullptr); - e.compass_y = strtof(row[11], nullptr); - e.compass_z = strtof(row[12], nullptr); - e.safe_return_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.safe_return_x = strtof(row[14], nullptr); - e.safe_return_y = strtof(row[15], nullptr); - e.safe_return_z = strtof(row[16], nullptr); - e.safe_return_heading = strtof(row[17], nullptr); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_heading = strtof(row[21], nullptr); - e.has_zone_in = static_cast(strtoul(row[22], nullptr, 10)); + e.compass_zone_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.compass_x = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_y = row[11] ? strtof(row[11], nullptr) : 0; + e.compass_z = row[12] ? strtof(row[12], nullptr) : 0; + e.safe_return_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.safe_return_x = row[14] ? strtof(row[14], nullptr) : 0; + e.safe_return_y = row[15] ? strtof(row[15], nullptr) : 0; + e.safe_return_z = row[16] ? strtof(row[16], nullptr) : 0; + e.safe_return_heading = row[17] ? strtof(row[17], nullptr) : 0; + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_heading = row[21] ? strtof(row[21], nullptr) : 0; + e.has_zone_in = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -456,29 +457,29 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { DynamicZones e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.instance_id = static_cast(atoi(row[1])); - e.type = static_cast(strtoul(row[2], nullptr, 10)); + e.type = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.uuid = row[3] ? row[3] : ""; e.name = row[4] ? row[4] : ""; - e.leader_id = static_cast(strtoul(row[5], nullptr, 10)); - e.min_players = static_cast(strtoul(row[6], nullptr, 10)); - e.max_players = static_cast(strtoul(row[7], nullptr, 10)); + e.leader_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.min_players = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.max_players = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.dz_switch_id = static_cast(atoi(row[8])); - e.compass_zone_id = static_cast(strtoul(row[9], nullptr, 10)); - e.compass_x = strtof(row[10], nullptr); - e.compass_y = strtof(row[11], nullptr); - e.compass_z = strtof(row[12], nullptr); - e.safe_return_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.safe_return_x = strtof(row[14], nullptr); - e.safe_return_y = strtof(row[15], nullptr); - e.safe_return_z = strtof(row[16], nullptr); - e.safe_return_heading = strtof(row[17], nullptr); - e.zone_in_x = strtof(row[18], nullptr); - e.zone_in_y = strtof(row[19], nullptr); - e.zone_in_z = strtof(row[20], nullptr); - e.zone_in_heading = strtof(row[21], nullptr); - e.has_zone_in = static_cast(strtoul(row[22], nullptr, 10)); + e.compass_zone_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.compass_x = row[10] ? strtof(row[10], nullptr) : 0; + e.compass_y = row[11] ? strtof(row[11], nullptr) : 0; + e.compass_z = row[12] ? strtof(row[12], nullptr) : 0; + e.safe_return_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.safe_return_x = row[14] ? strtof(row[14], nullptr) : 0; + e.safe_return_y = row[15] ? strtof(row[15], nullptr) : 0; + e.safe_return_z = row[16] ? strtof(row[16], nullptr) : 0; + e.safe_return_heading = row[17] ? strtof(row[17], nullptr) : 0; + e.zone_in_x = row[18] ? strtof(row[18], nullptr) : 0; + e.zone_in_y = row[19] ? strtof(row[19], nullptr) : 0; + e.zone_in_z = row[20] ? strtof(row[20], nullptr) : 0; + e.zone_in_heading = row[21] ? strtof(row[21], nullptr) : 0; + e.has_zone_in = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -537,6 +538,106 @@ 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 DynamicZones &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.uuid) + "'"); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.leader_id)); + v.push_back(std::to_string(e.min_players)); + v.push_back(std::to_string(e.max_players)); + v.push_back(std::to_string(e.dz_switch_id)); + v.push_back(std::to_string(e.compass_zone_id)); + v.push_back(std::to_string(e.compass_x)); + v.push_back(std::to_string(e.compass_y)); + v.push_back(std::to_string(e.compass_z)); + v.push_back(std::to_string(e.safe_return_zone_id)); + v.push_back(std::to_string(e.safe_return_x)); + v.push_back(std::to_string(e.safe_return_y)); + v.push_back(std::to_string(e.safe_return_z)); + v.push_back(std::to_string(e.safe_return_heading)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_z)); + v.push_back(std::to_string(e.zone_in_heading)); + v.push_back(std::to_string(e.has_zone_in)); + + 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(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.uuid) + "'"); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.leader_id)); + v.push_back(std::to_string(e.min_players)); + v.push_back(std::to_string(e.max_players)); + v.push_back(std::to_string(e.dz_switch_id)); + v.push_back(std::to_string(e.compass_zone_id)); + v.push_back(std::to_string(e.compass_x)); + v.push_back(std::to_string(e.compass_y)); + v.push_back(std::to_string(e.compass_z)); + v.push_back(std::to_string(e.safe_return_zone_id)); + v.push_back(std::to_string(e.safe_return_x)); + v.push_back(std::to_string(e.safe_return_y)); + v.push_back(std::to_string(e.safe_return_z)); + v.push_back(std::to_string(e.safe_return_heading)); + v.push_back(std::to_string(e.zone_in_x)); + v.push_back(std::to_string(e.zone_in_y)); + v.push_back(std::to_string(e.zone_in_z)); + v.push_back(std::to_string(e.zone_in_heading)); + v.push_back(std::to_string(e.has_zone_in)); + + 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_DYNAMIC_ZONES_REPOSITORY_H diff --git a/common/repositories/base/base_expedition_lockouts_repository.h b/common/repositories/base/base_expedition_lockouts_repository.h index e37dce650..b4ec21804 100644 --- a/common/repositories/base/base_expedition_lockouts_repository.h +++ b/common/repositories/base/base_expedition_lockouts_repository.h @@ -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_EXPEDITION_LOCKOUTS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), expedition_lockouts_id ) ); @@ -134,11 +135,11 @@ public: if (results.RowCount() == 1) { ExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.expedition_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.expedition_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_name = row[2] ? row[2] : ""; e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[4], nullptr, 10)); + e.duration = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.from_expedition_uuid = row[5] ? row[5] : ""; return e; @@ -273,11 +274,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { ExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.expedition_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.expedition_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_name = row[2] ? row[2] : ""; e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[4], nullptr, 10)); + e.duration = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.from_expedition_uuid = row[5] ? row[5] : ""; all_entries.push_back(e); @@ -303,11 +304,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { ExpeditionLockouts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.expedition_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.expedition_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_name = row[2] ? row[2] : ""; e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); - e.duration = static_cast(strtoul(row[4], nullptr, 10)); + e.duration = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.from_expedition_uuid = row[5] ? row[5] : ""; all_entries.push_back(e); @@ -367,6 +368,72 @@ 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 ExpeditionLockouts &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.expedition_id)); + v.push_back("'" + Strings::Escape(e.event_name) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back(std::to_string(e.duration)); + v.push_back("'" + Strings::Escape(e.from_expedition_uuid) + "'"); + + 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(std::to_string(e.expedition_id)); + v.push_back("'" + Strings::Escape(e.event_name) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back(std::to_string(e.duration)); + v.push_back("'" + Strings::Escape(e.from_expedition_uuid) + "'"); + + 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_EXPEDITION_LOCKOUTS_REPOSITORY_H diff --git a/common/repositories/base/base_expeditions_repository.h b/common/repositories/base/base_expeditions_repository.h index deaa3a01f..b4dff8502 100644 --- a/common/repositories/base/base_expeditions_repository.h +++ b/common/repositories/base/base_expeditions_repository.h @@ -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_EXPEDITIONS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), expeditions_id ) ); @@ -126,10 +127,10 @@ public: if (results.RowCount() == 1) { Expeditions e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.add_replay_on_join = static_cast(strtoul(row[2], nullptr, 10)); - e.is_locked = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.add_replay_on_join = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.is_locked = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -257,10 +258,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Expeditions e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.add_replay_on_join = static_cast(strtoul(row[2], nullptr, 10)); - e.is_locked = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.add_replay_on_join = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.is_locked = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -285,10 +286,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Expeditions e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); - e.add_replay_on_join = static_cast(strtoul(row[2], nullptr, 10)); - e.is_locked = static_cast(strtoul(row[3], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.add_replay_on_join = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.is_locked = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -347,6 +348,68 @@ 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 Expeditions &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.dynamic_zone_id)); + v.push_back(std::to_string(e.add_replay_on_join)); + v.push_back(std::to_string(e.is_locked)); + + 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(std::to_string(e.dynamic_zone_id)); + v.push_back(std::to_string(e.add_replay_on_join)); + v.push_back(std::to_string(e.is_locked)); + + 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_EXPEDITIONS_REPOSITORY_H diff --git a/common/repositories/base/base_faction_association_repository.h b/common/repositories/base/base_faction_association_repository.h index 029a355b6..3287f997e 100644 --- a/common/repositories/base/base_faction_association_repository.h +++ b/common/repositories/base/base_faction_association_repository.h @@ -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_FACTION_ASSOCIATION_REPOSITORY_H @@ -184,8 +184,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), faction_association_id ) ); @@ -196,25 +197,25 @@ public: e.id = static_cast(atoi(row[0])); e.id_1 = static_cast(atoi(row[1])); - e.mod_1 = strtof(row[2], nullptr); + e.mod_1 = row[2] ? strtof(row[2], nullptr) : 0; e.id_2 = static_cast(atoi(row[3])); - e.mod_2 = strtof(row[4], nullptr); + e.mod_2 = row[4] ? strtof(row[4], nullptr) : 0; e.id_3 = static_cast(atoi(row[5])); - e.mod_3 = strtof(row[6], nullptr); + e.mod_3 = row[6] ? strtof(row[6], nullptr) : 0; e.id_4 = static_cast(atoi(row[7])); - e.mod_4 = strtof(row[8], nullptr); + e.mod_4 = row[8] ? strtof(row[8], nullptr) : 0; e.id_5 = static_cast(atoi(row[9])); - e.mod_5 = strtof(row[10], nullptr); + e.mod_5 = row[10] ? strtof(row[10], nullptr) : 0; e.id_6 = static_cast(atoi(row[11])); - e.mod_6 = strtof(row[12], nullptr); + e.mod_6 = row[12] ? strtof(row[12], nullptr) : 0; e.id_7 = static_cast(atoi(row[13])); - e.mod_7 = strtof(row[14], nullptr); + e.mod_7 = row[14] ? strtof(row[14], nullptr) : 0; e.id_8 = static_cast(atoi(row[15])); - e.mod_8 = strtof(row[16], nullptr); + e.mod_8 = row[16] ? strtof(row[16], nullptr) : 0; e.id_9 = static_cast(atoi(row[17])); - e.mod_9 = strtof(row[18], nullptr); + e.mod_9 = row[18] ? strtof(row[18], nullptr) : 0; e.id_10 = static_cast(atoi(row[19])); - e.mod_10 = strtof(row[20], nullptr); + e.mod_10 = row[20] ? strtof(row[20], nullptr) : 0; return e; } @@ -396,25 +397,25 @@ public: e.id = static_cast(atoi(row[0])); e.id_1 = static_cast(atoi(row[1])); - e.mod_1 = strtof(row[2], nullptr); + e.mod_1 = row[2] ? strtof(row[2], nullptr) : 0; e.id_2 = static_cast(atoi(row[3])); - e.mod_2 = strtof(row[4], nullptr); + e.mod_2 = row[4] ? strtof(row[4], nullptr) : 0; e.id_3 = static_cast(atoi(row[5])); - e.mod_3 = strtof(row[6], nullptr); + e.mod_3 = row[6] ? strtof(row[6], nullptr) : 0; e.id_4 = static_cast(atoi(row[7])); - e.mod_4 = strtof(row[8], nullptr); + e.mod_4 = row[8] ? strtof(row[8], nullptr) : 0; e.id_5 = static_cast(atoi(row[9])); - e.mod_5 = strtof(row[10], nullptr); + e.mod_5 = row[10] ? strtof(row[10], nullptr) : 0; e.id_6 = static_cast(atoi(row[11])); - e.mod_6 = strtof(row[12], nullptr); + e.mod_6 = row[12] ? strtof(row[12], nullptr) : 0; e.id_7 = static_cast(atoi(row[13])); - e.mod_7 = strtof(row[14], nullptr); + e.mod_7 = row[14] ? strtof(row[14], nullptr) : 0; e.id_8 = static_cast(atoi(row[15])); - e.mod_8 = strtof(row[16], nullptr); + e.mod_8 = row[16] ? strtof(row[16], nullptr) : 0; e.id_9 = static_cast(atoi(row[17])); - e.mod_9 = strtof(row[18], nullptr); + e.mod_9 = row[18] ? strtof(row[18], nullptr) : 0; e.id_10 = static_cast(atoi(row[19])); - e.mod_10 = strtof(row[20], nullptr); + e.mod_10 = row[20] ? strtof(row[20], nullptr) : 0; all_entries.push_back(e); } @@ -441,25 +442,25 @@ public: e.id = static_cast(atoi(row[0])); e.id_1 = static_cast(atoi(row[1])); - e.mod_1 = strtof(row[2], nullptr); + e.mod_1 = row[2] ? strtof(row[2], nullptr) : 0; e.id_2 = static_cast(atoi(row[3])); - e.mod_2 = strtof(row[4], nullptr); + e.mod_2 = row[4] ? strtof(row[4], nullptr) : 0; e.id_3 = static_cast(atoi(row[5])); - e.mod_3 = strtof(row[6], nullptr); + e.mod_3 = row[6] ? strtof(row[6], nullptr) : 0; e.id_4 = static_cast(atoi(row[7])); - e.mod_4 = strtof(row[8], nullptr); + e.mod_4 = row[8] ? strtof(row[8], nullptr) : 0; e.id_5 = static_cast(atoi(row[9])); - e.mod_5 = strtof(row[10], nullptr); + e.mod_5 = row[10] ? strtof(row[10], nullptr) : 0; e.id_6 = static_cast(atoi(row[11])); - e.mod_6 = strtof(row[12], nullptr); + e.mod_6 = row[12] ? strtof(row[12], nullptr) : 0; e.id_7 = static_cast(atoi(row[13])); - e.mod_7 = strtof(row[14], nullptr); + e.mod_7 = row[14] ? strtof(row[14], nullptr) : 0; e.id_8 = static_cast(atoi(row[15])); - e.mod_8 = strtof(row[16], nullptr); + e.mod_8 = row[16] ? strtof(row[16], nullptr) : 0; e.id_9 = static_cast(atoi(row[17])); - e.mod_9 = strtof(row[18], nullptr); + e.mod_9 = row[18] ? strtof(row[18], nullptr) : 0; e.id_10 = static_cast(atoi(row[19])); - e.mod_10 = strtof(row[20], nullptr); + e.mod_10 = row[20] ? strtof(row[20], nullptr) : 0; all_entries.push_back(e); } @@ -518,6 +519,102 @@ 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 FactionAssociation &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.id_1)); + v.push_back(std::to_string(e.mod_1)); + v.push_back(std::to_string(e.id_2)); + v.push_back(std::to_string(e.mod_2)); + v.push_back(std::to_string(e.id_3)); + v.push_back(std::to_string(e.mod_3)); + v.push_back(std::to_string(e.id_4)); + v.push_back(std::to_string(e.mod_4)); + v.push_back(std::to_string(e.id_5)); + v.push_back(std::to_string(e.mod_5)); + v.push_back(std::to_string(e.id_6)); + v.push_back(std::to_string(e.mod_6)); + v.push_back(std::to_string(e.id_7)); + v.push_back(std::to_string(e.mod_7)); + v.push_back(std::to_string(e.id_8)); + v.push_back(std::to_string(e.mod_8)); + v.push_back(std::to_string(e.id_9)); + v.push_back(std::to_string(e.mod_9)); + v.push_back(std::to_string(e.id_10)); + v.push_back(std::to_string(e.mod_10)); + + 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(std::to_string(e.id_1)); + v.push_back(std::to_string(e.mod_1)); + v.push_back(std::to_string(e.id_2)); + v.push_back(std::to_string(e.mod_2)); + v.push_back(std::to_string(e.id_3)); + v.push_back(std::to_string(e.mod_3)); + v.push_back(std::to_string(e.id_4)); + v.push_back(std::to_string(e.mod_4)); + v.push_back(std::to_string(e.id_5)); + v.push_back(std::to_string(e.mod_5)); + v.push_back(std::to_string(e.id_6)); + v.push_back(std::to_string(e.mod_6)); + v.push_back(std::to_string(e.id_7)); + v.push_back(std::to_string(e.mod_7)); + v.push_back(std::to_string(e.id_8)); + v.push_back(std::to_string(e.mod_8)); + v.push_back(std::to_string(e.id_9)); + v.push_back(std::to_string(e.mod_9)); + v.push_back(std::to_string(e.id_10)); + v.push_back(std::to_string(e.mod_10)); + + 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_FACTION_ASSOCIATION_REPOSITORY_H diff --git a/common/repositories/base/base_faction_base_data_repository.h b/common/repositories/base/base_faction_base_data_repository.h index 3068d38bd..2ddd58f03 100644 --- a/common/repositories/base/base_faction_base_data_repository.h +++ b/common/repositories/base/base_faction_base_data_repository.h @@ -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_FACTION_BASE_DATA_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), faction_base_data_id ) ); @@ -368,6 +369,72 @@ 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 FactionBaseData &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.client_faction_id)); + v.push_back(std::to_string(e.min)); + v.push_back(std::to_string(e.max)); + v.push_back(std::to_string(e.unk_hero1)); + v.push_back(std::to_string(e.unk_hero2)); + v.push_back(std::to_string(e.unk_hero3)); + + 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.client_faction_id)); + v.push_back(std::to_string(e.min)); + v.push_back(std::to_string(e.max)); + v.push_back(std::to_string(e.unk_hero1)); + v.push_back(std::to_string(e.unk_hero2)); + v.push_back(std::to_string(e.unk_hero3)); + + 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_FACTION_BASE_DATA_REPOSITORY_H diff --git a/common/repositories/base/base_faction_list_mod_repository.h b/common/repositories/base/base_faction_list_mod_repository.h index 26df4e6cb..774eafa76 100644 --- a/common/repositories/base/base_faction_list_mod_repository.h +++ b/common/repositories/base/base_faction_list_mod_repository.h @@ -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_FACTION_LIST_MOD_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), faction_list_mod_id ) ); @@ -126,8 +127,8 @@ public: if (results.RowCount() == 1) { FactionListMod e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.mod = static_cast(atoi(row[2])); e.mod_name = row[3] ? row[3] : ""; @@ -257,8 +258,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { FactionListMod e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.mod = static_cast(atoi(row[2])); e.mod_name = row[3] ? row[3] : ""; @@ -285,8 +286,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { FactionListMod e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.mod = static_cast(atoi(row[2])); e.mod_name = row[3] ? row[3] : ""; @@ -347,6 +348,68 @@ 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 FactionListMod &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.mod)); + v.push_back("'" + Strings::Escape(e.mod_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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.mod)); + v.push_back("'" + Strings::Escape(e.mod_name) + "'"); + + 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_FACTION_LIST_MOD_REPOSITORY_H diff --git a/common/repositories/base/base_faction_list_repository.h b/common/repositories/base/base_faction_list_repository.h index 6d2398187..6d3c013e4 100644 --- a/common/repositories/base/base_faction_list_repository.h +++ b/common/repositories/base/base_faction_list_repository.h @@ -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_FACTION_LIST_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), faction_list_id ) ); @@ -338,6 +339,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 FactionList &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.base)); + + 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.name) + "'"); + v.push_back(std::to_string(e.base)); + + 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_FACTION_LIST_REPOSITORY_H diff --git a/common/repositories/base/base_faction_values_repository.h b/common/repositories/base/base_faction_values_repository.h index 5c2f134db..edce0d9f7 100644 --- a/common/repositories/base/base_faction_values_repository.h +++ b/common/repositories/base/base_faction_values_repository.h @@ -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_FACTION_VALUES_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), faction_values_id ) ); @@ -348,6 +349,68 @@ 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 FactionValues &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.current_value)); + v.push_back(std::to_string(e.temp)); + + 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.char_id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.current_value)); + v.push_back(std::to_string(e.temp)); + + 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_FACTION_VALUES_REPOSITORY_H diff --git a/common/repositories/base/base_fishing_repository.h b/common/repositories/base/base_fishing_repository.h index c04886654..578ae4212 100644 --- a/common/repositories/base/base_fishing_repository.h +++ b/common/repositories/base/base_fishing_repository.h @@ -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_FISHING_REPOSITORY_H @@ -144,8 +144,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), fishing_id ) ); @@ -417,6 +418,82 @@ 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 Fishing &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.Itemid)); + v.push_back(std::to_string(e.skill_level)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.npc_id)); + v.push_back(std::to_string(e.npc_chance)); + 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) + "'"); + + 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(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.Itemid)); + v.push_back(std::to_string(e.skill_level)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.npc_id)); + v.push_back(std::to_string(e.npc_chance)); + 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) + "'"); + + 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_FISHING_REPOSITORY_H diff --git a/common/repositories/base/base_forage_repository.h b/common/repositories/base/base_forage_repository.h index 609af148e..66007f5e0 100644 --- a/common/repositories/base/base_forage_repository.h +++ b/common/repositories/base/base_forage_repository.h @@ -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_FORAGE_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), forage_id ) ); @@ -397,6 +398,78 @@ 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 Forage &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.Itemid)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.chance)); + 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) + "'"); + + 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(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.Itemid)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.chance)); + 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) + "'"); + + 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_FORAGE_REPOSITORY_H diff --git a/common/repositories/base/base_friends_repository.h b/common/repositories/base/base_friends_repository.h index 1f9acf7be..84d7ba594 100644 --- a/common/repositories/base/base_friends_repository.h +++ b/common/repositories/base/base_friends_repository.h @@ -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_FRIENDS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), friends_id ) ); @@ -122,8 +123,8 @@ public: if (results.RowCount() == 1) { Friends e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.name = row[2] ? row[2] : ""; return e; @@ -250,8 +251,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Friends e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.name = row[2] ? row[2] : ""; all_entries.push_back(e); @@ -277,8 +278,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Friends e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.name = row[2] ? row[2] : ""; all_entries.push_back(e); @@ -338,6 +339,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 Friends &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + + 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_FRIENDS_REPOSITORY_H diff --git a/common/repositories/base/base_global_loot_repository.h b/common/repositories/base/base_global_loot_repository.h index c8755d267..fe657219e 100644 --- a/common/repositories/base/base_global_loot_repository.h +++ b/common/repositories/base/base_global_loot_repository.h @@ -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_GLOBAL_LOOT_REPOSITORY_H @@ -168,8 +168,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), global_loot_id ) ); @@ -477,6 +478,94 @@ 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 GlobalLoot &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.description) + "'"); + v.push_back(std::to_string(e.loottable_id)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.rare)); + v.push_back(std::to_string(e.raid)); + v.push_back("'" + Strings::Escape(e.race) + "'"); + v.push_back("'" + Strings::Escape(e.class_) + "'"); + v.push_back("'" + Strings::Escape(e.bodytype) + "'"); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.hot_zone)); + 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) + "'"); + + 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.description) + "'"); + v.push_back(std::to_string(e.loottable_id)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.rare)); + v.push_back(std::to_string(e.raid)); + v.push_back("'" + Strings::Escape(e.race) + "'"); + v.push_back("'" + Strings::Escape(e.class_) + "'"); + v.push_back("'" + Strings::Escape(e.bodytype) + "'"); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.hot_zone)); + 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) + "'"); + + 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_GLOBAL_LOOT_REPOSITORY_H diff --git a/common/repositories/base/base_gm_ips_repository.h b/common/repositories/base/base_gm_ips_repository.h index ae1f52ef9..57a21654b 100644 --- a/common/repositories/base/base_gm_ips_repository.h +++ b/common/repositories/base/base_gm_ips_repository.h @@ -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_GM_IPS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), gm_ips_id ) ); @@ -338,6 +339,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 GmIps &e + ) + { + std::vector v; + + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.account_id)); + v.push_back("'" + Strings::Escape(e.ip_address) + "'"); + + 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("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.account_id)); + v.push_back("'" + Strings::Escape(e.ip_address) + "'"); + + 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_GM_IPS_REPOSITORY_H diff --git a/common/repositories/base/base_graveyard_repository.h b/common/repositories/base/base_graveyard_repository.h index 1cc7d5c1e..50d5f79c0 100644 --- a/common/repositories/base/base_graveyard_repository.h +++ b/common/repositories/base/base_graveyard_repository.h @@ -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_GRAVEYARD_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), graveyard_id ) ); @@ -136,10 +137,10 @@ public: e.id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); - e.x = strtof(row[2], nullptr); - e.y = strtof(row[3], nullptr); - e.z = strtof(row[4], nullptr); - e.heading = strtof(row[5], nullptr); + e.x = row[2] ? strtof(row[2], nullptr) : 0; + e.y = row[3] ? strtof(row[3], nullptr) : 0; + e.z = row[4] ? strtof(row[4], nullptr) : 0; + e.heading = row[5] ? strtof(row[5], nullptr) : 0; return e; } @@ -275,10 +276,10 @@ public: e.id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); - e.x = strtof(row[2], nullptr); - e.y = strtof(row[3], nullptr); - e.z = strtof(row[4], nullptr); - e.heading = strtof(row[5], nullptr); + e.x = row[2] ? strtof(row[2], nullptr) : 0; + e.y = row[3] ? strtof(row[3], nullptr) : 0; + e.z = row[4] ? strtof(row[4], nullptr) : 0; + e.heading = row[5] ? strtof(row[5], nullptr) : 0; all_entries.push_back(e); } @@ -305,10 +306,10 @@ public: e.id = static_cast(atoi(row[0])); e.zone_id = static_cast(atoi(row[1])); - e.x = strtof(row[2], nullptr); - e.y = strtof(row[3], nullptr); - e.z = strtof(row[4], nullptr); - e.heading = strtof(row[5], nullptr); + e.x = row[2] ? strtof(row[2], nullptr) : 0; + e.y = row[3] ? strtof(row[3], nullptr) : 0; + e.z = row[4] ? strtof(row[4], nullptr) : 0; + e.heading = row[5] ? strtof(row[5], nullptr) : 0; all_entries.push_back(e); } @@ -367,6 +368,72 @@ 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 Graveyard &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + 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)); + v.push_back(std::to_string(e.heading)); + + 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(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)); + v.push_back(std::to_string(e.heading)); + + 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_GRAVEYARD_REPOSITORY_H diff --git a/common/repositories/base/base_grid_entries_repository.h b/common/repositories/base/base_grid_entries_repository.h index b4fafb192..97e7cd83a 100644 --- a/common/repositories/base/base_grid_entries_repository.h +++ b/common/repositories/base/base_grid_entries_repository.h @@ -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_GRID_ENTRIES_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), grid_entries_id ) ); @@ -149,10 +150,10 @@ public: e.gridid = static_cast(atoi(row[0])); e.zoneid = static_cast(atoi(row[1])); e.number = static_cast(atoi(row[2])); - e.x = strtof(row[3], nullptr); - e.y = strtof(row[4], nullptr); - e.z = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.x = row[3] ? strtof(row[3], nullptr) : 0; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.z = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.pause = static_cast(atoi(row[7])); e.centerpoint = static_cast(atoi(row[8])); @@ -301,10 +302,10 @@ public: e.gridid = static_cast(atoi(row[0])); e.zoneid = static_cast(atoi(row[1])); e.number = static_cast(atoi(row[2])); - e.x = strtof(row[3], nullptr); - e.y = strtof(row[4], nullptr); - e.z = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.x = row[3] ? strtof(row[3], nullptr) : 0; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.z = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.pause = static_cast(atoi(row[7])); e.centerpoint = static_cast(atoi(row[8])); @@ -334,10 +335,10 @@ public: e.gridid = static_cast(atoi(row[0])); e.zoneid = static_cast(atoi(row[1])); e.number = static_cast(atoi(row[2])); - e.x = strtof(row[3], nullptr); - e.y = strtof(row[4], nullptr); - e.z = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.x = row[3] ? strtof(row[3], nullptr) : 0; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.z = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.pause = static_cast(atoi(row[7])); e.centerpoint = static_cast(atoi(row[8])); @@ -398,6 +399,78 @@ 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 GridEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.gridid)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.number)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.pause)); + v.push_back(std::to_string(e.centerpoint)); + + 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.gridid)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.number)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.pause)); + v.push_back(std::to_string(e.centerpoint)); + + 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_GRID_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_grid_repository.h b/common/repositories/base/base_grid_repository.h index e37e7971a..2c0d5d7dd 100644 --- a/common/repositories/base/base_grid_repository.h +++ b/common/repositories/base/base_grid_repository.h @@ -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_GRID_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), grid_id ) ); @@ -348,6 +349,68 @@ 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 Grid &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.type2)); + + 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(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.type2)); + + 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_GRID_REPOSITORY_H diff --git a/common/repositories/base/base_ground_spawns_repository.h b/common/repositories/base/base_ground_spawns_repository.h index b9c534c13..077b05319 100644 --- a/common/repositories/base/base_ground_spawns_repository.h +++ b/common/repositories/base/base_ground_spawns_repository.h @@ -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_GROUND_SPAWNS_REPOSITORY_H @@ -172,8 +172,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), ground_spawns_id ) ); @@ -182,20 +183,20 @@ public: if (results.RowCount() == 1) { GroundSpawns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.max_x = strtof(row[3], nullptr); - e.max_y = strtof(row[4], nullptr); - e.max_z = strtof(row[5], nullptr); - e.min_x = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.max_x = row[3] ? strtof(row[3], nullptr) : 2000; + e.max_y = row[4] ? strtof(row[4], nullptr) : 2000; + e.max_z = row[5] ? strtof(row[5], nullptr) : 10000; + e.min_x = row[6] ? strtof(row[6], nullptr) : -2000; + e.min_y = row[7] ? strtof(row[7], nullptr) : -2000; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.name = row[9] ? row[9] : ""; - e.item = static_cast(strtoul(row[10], nullptr, 10)); - e.max_allowed = static_cast(strtoul(row[11], nullptr, 10)); + e.item = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_allowed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 1; e.comment = row[12] ? row[12] : ""; - e.respawn_timer = static_cast(strtoul(row[13], nullptr, 10)); + e.respawn_timer = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 300; e.min_expansion = static_cast(atoi(row[14])); e.max_expansion = static_cast(atoi(row[15])); e.content_flags = row[16] ? row[16] : ""; @@ -369,20 +370,20 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GroundSpawns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.max_x = strtof(row[3], nullptr); - e.max_y = strtof(row[4], nullptr); - e.max_z = strtof(row[5], nullptr); - e.min_x = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.max_x = row[3] ? strtof(row[3], nullptr) : 2000; + e.max_y = row[4] ? strtof(row[4], nullptr) : 2000; + e.max_z = row[5] ? strtof(row[5], nullptr) : 10000; + e.min_x = row[6] ? strtof(row[6], nullptr) : -2000; + e.min_y = row[7] ? strtof(row[7], nullptr) : -2000; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.name = row[9] ? row[9] : ""; - e.item = static_cast(strtoul(row[10], nullptr, 10)); - e.max_allowed = static_cast(strtoul(row[11], nullptr, 10)); + e.item = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_allowed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 1; e.comment = row[12] ? row[12] : ""; - e.respawn_timer = static_cast(strtoul(row[13], nullptr, 10)); + e.respawn_timer = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 300; e.min_expansion = static_cast(atoi(row[14])); e.max_expansion = static_cast(atoi(row[15])); e.content_flags = row[16] ? row[16] : ""; @@ -411,20 +412,20 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GroundSpawns e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.max_x = strtof(row[3], nullptr); - e.max_y = strtof(row[4], nullptr); - e.max_z = strtof(row[5], nullptr); - e.min_x = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.max_x = row[3] ? strtof(row[3], nullptr) : 2000; + e.max_y = row[4] ? strtof(row[4], nullptr) : 2000; + e.max_z = row[5] ? strtof(row[5], nullptr) : 10000; + e.min_x = row[6] ? strtof(row[6], nullptr) : -2000; + e.min_y = row[7] ? strtof(row[7], nullptr) : -2000; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.name = row[9] ? row[9] : ""; - e.item = static_cast(strtoul(row[10], nullptr, 10)); - e.max_allowed = static_cast(strtoul(row[11], nullptr, 10)); + e.item = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_allowed = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 1; e.comment = row[12] ? row[12] : ""; - e.respawn_timer = static_cast(strtoul(row[13], nullptr, 10)); + e.respawn_timer = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 300; e.min_expansion = static_cast(atoi(row[14])); e.max_expansion = static_cast(atoi(row[15])); e.content_flags = row[16] ? row[16] : ""; @@ -487,6 +488,96 @@ 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 GroundSpawns &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.max_x)); + v.push_back(std::to_string(e.max_y)); + v.push_back(std::to_string(e.max_z)); + v.push_back(std::to_string(e.min_x)); + v.push_back(std::to_string(e.min_y)); + v.push_back(std::to_string(e.heading)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.item)); + v.push_back(std::to_string(e.max_allowed)); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.respawn_timer)); + 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) + "'"); + + 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(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.max_x)); + v.push_back(std::to_string(e.max_y)); + v.push_back(std::to_string(e.max_z)); + v.push_back(std::to_string(e.min_x)); + v.push_back(std::to_string(e.min_y)); + v.push_back(std::to_string(e.heading)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.item)); + v.push_back(std::to_string(e.max_allowed)); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.respawn_timer)); + 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) + "'"); + + 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_GROUND_SPAWNS_REPOSITORY_H diff --git a/common/repositories/base/base_group_id_repository.h b/common/repositories/base/base_group_id_repository.h index 628e814d4..36800d86c 100644 --- a/common/repositories/base/base_group_id_repository.h +++ b/common/repositories/base/base_group_id_repository.h @@ -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_GROUP_ID_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), group_id_id ) ); @@ -348,6 +349,68 @@ 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 GroupId &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.groupid)); + v.push_back(std::to_string(e.charid)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.ismerc)); + + 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.groupid)); + v.push_back(std::to_string(e.charid)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.ismerc)); + + 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_GROUP_ID_REPOSITORY_H diff --git a/common/repositories/base/base_group_leaders_repository.h b/common/repositories/base/base_group_leaders_repository.h index 5032bf65f..c760caf90 100644 --- a/common/repositories/base/base_group_leaders_repository.h +++ b/common/repositories/base/base_group_leaders_repository.h @@ -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_GROUP_LEADERS_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), group_leaders_id ) ); @@ -398,6 +399,78 @@ 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 GroupLeaders &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.gid)); + v.push_back("'" + Strings::Escape(e.leadername) + "'"); + v.push_back("'" + Strings::Escape(e.marknpc) + "'"); + v.push_back("'" + Strings::Escape(e.leadershipaa) + "'"); + v.push_back("'" + Strings::Escape(e.maintank) + "'"); + v.push_back("'" + Strings::Escape(e.assist) + "'"); + v.push_back("'" + Strings::Escape(e.puller) + "'"); + v.push_back("'" + Strings::Escape(e.mentoree) + "'"); + v.push_back(std::to_string(e.mentor_percent)); + + 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.gid)); + v.push_back("'" + Strings::Escape(e.leadername) + "'"); + v.push_back("'" + Strings::Escape(e.marknpc) + "'"); + v.push_back("'" + Strings::Escape(e.leadershipaa) + "'"); + v.push_back("'" + Strings::Escape(e.maintank) + "'"); + v.push_back("'" + Strings::Escape(e.assist) + "'"); + v.push_back("'" + Strings::Escape(e.puller) + "'"); + v.push_back("'" + Strings::Escape(e.mentoree) + "'"); + v.push_back(std::to_string(e.mentor_percent)); + + 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_GROUP_LEADERS_REPOSITORY_H diff --git a/common/repositories/base/base_guild_members_repository.h b/common/repositories/base/base_guild_members_repository.h new file mode 100644 index 000000000..0d3599e94 --- /dev/null +++ b/common/repositories/base/base_guild_members_repository.h @@ -0,0 +1,488 @@ +/** + * 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_MEMBERS_REPOSITORY_H +#define EQEMU_BASE_GUILD_MEMBERS_REPOSITORY_H + +#include "../../database.h" +#include "../../strings.h" +#include + +class BaseGuildMembersRepository { +public: + struct GuildMembers { + int32_t char_id; + uint32_t guild_id; + uint8_t rank; + uint8_t tribute_enable; + uint32_t total_tribute; + uint32_t last_tribute; + uint8_t banker; + std::string public_note; + uint8_t alt; + uint8_t online; + }; + + static std::string PrimaryKey() + { + return std::string("char_id"); + } + + static std::vector Columns() + { + return { + "char_id", + "guild_id", + "rank", + "tribute_enable", + "total_tribute", + "last_tribute", + "banker", + "public_note", + "alt", + "online", + }; + } + + static std::vector SelectColumns() + { + return { + "char_id", + "guild_id", + "rank", + "tribute_enable", + "total_tribute", + "last_tribute", + "banker", + "public_note", + "alt", + "online", + }; + } + + 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_members"); + } + + static std::string BaseSelect() + { + return fmt::format( + "SELECT {} FROM {}", + SelectColumnsRaw(), + TableName() + ); + } + + static std::string BaseInsert() + { + return fmt::format( + "INSERT INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static GuildMembers NewEntity() + { + GuildMembers e{}; + + e.char_id = 0; + e.guild_id = 0; + e.rank = 0; + e.tribute_enable = 0; + e.total_tribute = 0; + e.last_tribute = 0; + e.banker = 0; + e.public_note = ""; + e.alt = 0; + e.online = 0; + + return e; + } + + static GuildMembers GetGuildMembers( + const std::vector &guild_memberss, + int guild_members_id + ) + { + for (auto &guild_members : guild_memberss) { + if (guild_members.char_id == guild_members_id) { + return guild_members; + } + } + + return NewEntity(); + } + + static GuildMembers FindOne( + Database& db, + int guild_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "{} WHERE {} = {} LIMIT 1", + BaseSelect(), + PrimaryKey(), + guild_members_id + ) + ); + + auto row = results.begin(); + if (results.RowCount() == 1) { + GuildMembers e{}; + + e.char_id = static_cast(atoi(row[0])); + e.guild_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute_enable = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.total_tribute = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.last_tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.banker = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.public_note = row[7] ? row[7] : ""; + e.alt = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.online = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + + return e; + } + + return NewEntity(); + } + + static int DeleteOne( + Database& db, + int guild_members_id + ) + { + auto results = db.QueryDatabase( + fmt::format( + "DELETE FROM {} WHERE {} = {}", + TableName(), + PrimaryKey(), + guild_members_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static int UpdateOne( + Database& db, + const GuildMembers &e + ) + { + std::vector v; + + auto columns = Columns(); + + v.push_back(columns[0] + " = " + std::to_string(e.char_id)); + v.push_back(columns[1] + " = " + std::to_string(e.guild_id)); + v.push_back(columns[2] + " = " + std::to_string(e.rank)); + v.push_back(columns[3] + " = " + std::to_string(e.tribute_enable)); + v.push_back(columns[4] + " = " + std::to_string(e.total_tribute)); + v.push_back(columns[5] + " = " + std::to_string(e.last_tribute)); + v.push_back(columns[6] + " = " + std::to_string(e.banker)); + v.push_back(columns[7] + " = '" + Strings::Escape(e.public_note) + "'"); + v.push_back(columns[8] + " = " + std::to_string(e.alt)); + v.push_back(columns[9] + " = " + std::to_string(e.online)); + + auto results = db.QueryDatabase( + fmt::format( + "UPDATE {} SET {} WHERE {} = {}", + TableName(), + Strings::Implode(", ", v), + PrimaryKey(), + e.char_id + ) + ); + + return (results.Success() ? results.RowsAffected() : 0); + } + + static GuildMembers InsertOne( + Database& db, + GuildMembers e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + v.push_back(std::to_string(e.online)); + + auto results = db.QueryDatabase( + fmt::format( + "{} VALUES ({})", + BaseInsert(), + Strings::Implode(",", v) + ) + ); + + if (results.Success()) { + e.char_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.char_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + v.push_back(std::to_string(e.online)); + + 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) { + GuildMembers e{}; + + e.char_id = static_cast(atoi(row[0])); + e.guild_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute_enable = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.total_tribute = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.last_tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.banker = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.public_note = row[7] ? row[7] : ""; + e.alt = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.online = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 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) { + GuildMembers e{}; + + e.char_id = static_cast(atoi(row[0])); + e.guild_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.rank = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.tribute_enable = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.total_tribute = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.last_tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.banker = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.public_note = row[7] ? row[7] : ""; + e.alt = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.online = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 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 GuildMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + v.push_back(std::to_string(e.online)); + + 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.char_id)); + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.tribute_enable)); + v.push_back(std::to_string(e.total_tribute)); + v.push_back(std::to_string(e.last_tribute)); + v.push_back(std::to_string(e.banker)); + v.push_back("'" + Strings::Escape(e.public_note) + "'"); + v.push_back(std::to_string(e.alt)); + v.push_back(std::to_string(e.online)); + + 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_GUILD_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_guild_ranks_repository.h b/common/repositories/base/base_guild_ranks_repository.h index cbc4ddf64..5068e5204 100644 --- a/common/repositories/base/base_guild_ranks_repository.h +++ b/common/repositories/base/base_guild_ranks_repository.h @@ -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_GUILD_RANKS_REPOSITORY_H @@ -22,14 +22,6 @@ public: uint32_t guild_id; uint8_t rank; std::string title; - uint8_t can_hear; - uint8_t can_speak; - uint8_t can_invite; - uint8_t can_remove; - uint8_t can_promote; - uint8_t can_demote; - uint8_t can_motd; - uint8_t can_warpeace; }; static std::string PrimaryKey() @@ -43,14 +35,6 @@ public: "guild_id", "rank", "title", - "can_hear", - "can_speak", - "can_invite", - "can_remove", - "can_promote", - "can_demote", - "can_motd", - "can_warpeace", }; } @@ -60,14 +44,6 @@ public: "guild_id", "rank", "title", - "can_hear", - "can_speak", - "can_invite", - "can_remove", - "can_promote", - "can_demote", - "can_motd", - "can_warpeace", }; } @@ -108,17 +84,9 @@ public: { GuildRanks e{}; - e.guild_id = 0; - e.rank = 0; - e.title = ""; - e.can_hear = 0; - e.can_speak = 0; - e.can_invite = 0; - e.can_remove = 0; - e.can_promote = 0; - e.can_demote = 0; - e.can_motd = 0; - e.can_warpeace = 0; + e.guild_id = 0; + e.rank = 0; + e.title = ""; return e; } @@ -144,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), guild_ranks_id ) ); @@ -154,17 +123,9 @@ public: if (results.RowCount() == 1) { GuildRanks e{}; - e.guild_id = static_cast(strtoul(row[0], nullptr, 10)); - e.rank = static_cast(strtoul(row[1], nullptr, 10)); - e.title = row[2] ? row[2] : ""; - e.can_hear = static_cast(strtoul(row[3], nullptr, 10)); - e.can_speak = static_cast(strtoul(row[4], nullptr, 10)); - e.can_invite = static_cast(strtoul(row[5], nullptr, 10)); - e.can_remove = static_cast(strtoul(row[6], nullptr, 10)); - e.can_promote = static_cast(strtoul(row[7], nullptr, 10)); - e.can_demote = static_cast(strtoul(row[8], nullptr, 10)); - e.can_motd = static_cast(strtoul(row[9], nullptr, 10)); - e.can_warpeace = static_cast(strtoul(row[10], nullptr, 10)); + e.guild_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.rank = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title = row[2] ? row[2] : ""; return e; } @@ -201,14 +162,6 @@ public: v.push_back(columns[0] + " = " + std::to_string(e.guild_id)); v.push_back(columns[1] + " = " + std::to_string(e.rank)); v.push_back(columns[2] + " = '" + Strings::Escape(e.title) + "'"); - v.push_back(columns[3] + " = " + std::to_string(e.can_hear)); - v.push_back(columns[4] + " = " + std::to_string(e.can_speak)); - v.push_back(columns[5] + " = " + std::to_string(e.can_invite)); - v.push_back(columns[6] + " = " + std::to_string(e.can_remove)); - v.push_back(columns[7] + " = " + std::to_string(e.can_promote)); - v.push_back(columns[8] + " = " + std::to_string(e.can_demote)); - v.push_back(columns[9] + " = " + std::to_string(e.can_motd)); - v.push_back(columns[10] + " = " + std::to_string(e.can_warpeace)); auto results = db.QueryDatabase( fmt::format( @@ -233,14 +186,6 @@ public: v.push_back(std::to_string(e.guild_id)); v.push_back(std::to_string(e.rank)); v.push_back("'" + Strings::Escape(e.title) + "'"); - v.push_back(std::to_string(e.can_hear)); - v.push_back(std::to_string(e.can_speak)); - v.push_back(std::to_string(e.can_invite)); - v.push_back(std::to_string(e.can_remove)); - v.push_back(std::to_string(e.can_promote)); - v.push_back(std::to_string(e.can_demote)); - v.push_back(std::to_string(e.can_motd)); - v.push_back(std::to_string(e.can_warpeace)); auto results = db.QueryDatabase( fmt::format( @@ -273,14 +218,6 @@ public: v.push_back(std::to_string(e.guild_id)); v.push_back(std::to_string(e.rank)); v.push_back("'" + Strings::Escape(e.title) + "'"); - v.push_back(std::to_string(e.can_hear)); - v.push_back(std::to_string(e.can_speak)); - v.push_back(std::to_string(e.can_invite)); - v.push_back(std::to_string(e.can_remove)); - v.push_back(std::to_string(e.can_promote)); - v.push_back(std::to_string(e.can_demote)); - v.push_back(std::to_string(e.can_motd)); - v.push_back(std::to_string(e.can_warpeace)); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } @@ -314,17 +251,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GuildRanks e{}; - e.guild_id = static_cast(strtoul(row[0], nullptr, 10)); - e.rank = static_cast(strtoul(row[1], nullptr, 10)); - e.title = row[2] ? row[2] : ""; - e.can_hear = static_cast(strtoul(row[3], nullptr, 10)); - e.can_speak = static_cast(strtoul(row[4], nullptr, 10)); - e.can_invite = static_cast(strtoul(row[5], nullptr, 10)); - e.can_remove = static_cast(strtoul(row[6], nullptr, 10)); - e.can_promote = static_cast(strtoul(row[7], nullptr, 10)); - e.can_demote = static_cast(strtoul(row[8], nullptr, 10)); - e.can_motd = static_cast(strtoul(row[9], nullptr, 10)); - e.can_warpeace = static_cast(strtoul(row[10], nullptr, 10)); + e.guild_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.rank = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title = row[2] ? row[2] : ""; all_entries.push_back(e); } @@ -349,17 +278,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GuildRanks e{}; - e.guild_id = static_cast(strtoul(row[0], nullptr, 10)); - e.rank = static_cast(strtoul(row[1], nullptr, 10)); - e.title = row[2] ? row[2] : ""; - e.can_hear = static_cast(strtoul(row[3], nullptr, 10)); - e.can_speak = static_cast(strtoul(row[4], nullptr, 10)); - e.can_invite = static_cast(strtoul(row[5], nullptr, 10)); - e.can_remove = static_cast(strtoul(row[6], nullptr, 10)); - e.can_promote = static_cast(strtoul(row[7], nullptr, 10)); - e.can_demote = static_cast(strtoul(row[8], nullptr, 10)); - e.can_motd = static_cast(strtoul(row[9], nullptr, 10)); - e.can_warpeace = static_cast(strtoul(row[10], nullptr, 10)); + e.guild_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.rank = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title = row[2] ? row[2] : ""; all_entries.push_back(e); } @@ -418,6 +339,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 GuildRanks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back("'" + Strings::Escape(e.title) + "'"); + + 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.guild_id)); + v.push_back(std::to_string(e.rank)); + v.push_back("'" + Strings::Escape(e.title) + "'"); + + 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_GUILD_RANKS_REPOSITORY_H diff --git a/common/repositories/base/base_guild_relations_repository.h b/common/repositories/base/base_guild_relations_repository.h index 6208edadc..0c040d7de 100644 --- a/common/repositories/base/base_guild_relations_repository.h +++ b/common/repositories/base/base_guild_relations_repository.h @@ -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_GUILD_RELATIONS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), guild_relations_id ) ); @@ -122,8 +123,8 @@ public: if (results.RowCount() == 1) { GuildRelations e{}; - e.guild1 = static_cast(strtoul(row[0], nullptr, 10)); - e.guild2 = static_cast(strtoul(row[1], nullptr, 10)); + e.guild1 = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guild2 = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.relation = static_cast(atoi(row[2])); return e; @@ -250,8 +251,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GuildRelations e{}; - e.guild1 = static_cast(strtoul(row[0], nullptr, 10)); - e.guild2 = static_cast(strtoul(row[1], nullptr, 10)); + e.guild1 = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guild2 = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.relation = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -277,8 +278,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { GuildRelations e{}; - e.guild1 = static_cast(strtoul(row[0], nullptr, 10)); - e.guild2 = static_cast(strtoul(row[1], nullptr, 10)); + e.guild1 = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.guild2 = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.relation = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -338,6 +339,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 GuildRelations &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.guild1)); + v.push_back(std::to_string(e.guild2)); + v.push_back(std::to_string(e.relation)); + + 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.guild1)); + v.push_back(std::to_string(e.guild2)); + v.push_back(std::to_string(e.relation)); + + 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_GUILD_RELATIONS_REPOSITORY_H diff --git a/common/repositories/base/base_guilds_repository.h b/common/repositories/base/base_guilds_repository.h index a423eaaa7..ef6a4eeae 100644 --- a/common/repositories/base/base_guilds_repository.h +++ b/common/repositories/base/base_guilds_repository.h @@ -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_GUILDS_REPOSITORY_H @@ -28,6 +28,7 @@ public: std::string motd_setter; std::string channel; std::string url; + uint32_t favor; }; static std::string PrimaryKey() @@ -47,6 +48,7 @@ public: "motd_setter", "channel", "url", + "favor", }; } @@ -62,6 +64,7 @@ public: "motd_setter", "channel", "url", + "favor", }; } @@ -111,6 +114,7 @@ public: e.motd_setter = ""; e.channel = ""; e.url = ""; + e.favor = 0; return e; } @@ -136,8 +140,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), guilds_id ) ); @@ -151,10 +156,11 @@ public: e.leader = static_cast(atoi(row[2])); e.minstatus = static_cast(atoi(row[3])); e.motd = row[4] ? row[4] : ""; - e.tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.motd_setter = row[6] ? row[6] : ""; e.channel = row[7] ? row[7] : ""; e.url = row[8] ? row[8] : ""; + e.favor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; return e; } @@ -196,6 +202,7 @@ public: v.push_back(columns[6] + " = '" + Strings::Escape(e.motd_setter) + "'"); v.push_back(columns[7] + " = '" + Strings::Escape(e.channel) + "'"); v.push_back(columns[8] + " = '" + Strings::Escape(e.url) + "'"); + v.push_back(columns[9] + " = " + std::to_string(e.favor)); auto results = db.QueryDatabase( fmt::format( @@ -226,6 +233,7 @@ public: v.push_back("'" + Strings::Escape(e.motd_setter) + "'"); v.push_back("'" + Strings::Escape(e.channel) + "'"); v.push_back("'" + Strings::Escape(e.url) + "'"); + v.push_back(std::to_string(e.favor)); auto results = db.QueryDatabase( fmt::format( @@ -264,6 +272,7 @@ public: v.push_back("'" + Strings::Escape(e.motd_setter) + "'"); v.push_back("'" + Strings::Escape(e.channel) + "'"); v.push_back("'" + Strings::Escape(e.url) + "'"); + v.push_back(std::to_string(e.favor)); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } @@ -302,10 +311,11 @@ public: e.leader = static_cast(atoi(row[2])); e.minstatus = static_cast(atoi(row[3])); e.motd = row[4] ? row[4] : ""; - e.tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.motd_setter = row[6] ? row[6] : ""; e.channel = row[7] ? row[7] : ""; e.url = row[8] ? row[8] : ""; + e.favor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -335,10 +345,11 @@ public: e.leader = static_cast(atoi(row[2])); e.minstatus = static_cast(atoi(row[3])); e.motd = row[4] ? row[4] : ""; - e.tribute = static_cast(strtoul(row[5], nullptr, 10)); + e.tribute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.motd_setter = row[6] ? row[6] : ""; e.channel = row[7] ? row[7] : ""; e.url = row[8] ? row[8] : ""; + e.favor = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -397,6 +408,80 @@ 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 Guilds &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.leader)); + v.push_back(std::to_string(e.minstatus)); + v.push_back("'" + Strings::Escape(e.motd) + "'"); + v.push_back(std::to_string(e.tribute)); + v.push_back("'" + Strings::Escape(e.motd_setter) + "'"); + v.push_back("'" + Strings::Escape(e.channel) + "'"); + v.push_back("'" + Strings::Escape(e.url) + "'"); + v.push_back(std::to_string(e.favor)); + + 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.name) + "'"); + v.push_back(std::to_string(e.leader)); + v.push_back(std::to_string(e.minstatus)); + v.push_back("'" + Strings::Escape(e.motd) + "'"); + v.push_back(std::to_string(e.tribute)); + v.push_back("'" + Strings::Escape(e.motd_setter) + "'"); + v.push_back("'" + Strings::Escape(e.channel) + "'"); + v.push_back("'" + Strings::Escape(e.url) + "'"); + v.push_back(std::to_string(e.favor)); + + 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_GUILDS_REPOSITORY_H diff --git a/common/repositories/base/base_horses_repository.h b/common/repositories/base/base_horses_repository.h index a881720de..3b447852d 100644 --- a/common/repositories/base/base_horses_repository.h +++ b/common/repositories/base/base_horses_repository.h @@ -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_HORSES_REPOSITORY_H @@ -128,8 +128,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), horses_id ) ); @@ -143,7 +144,7 @@ public: e.race = static_cast(atoi(row[2])); e.gender = static_cast(atoi(row[3])); e.texture = static_cast(atoi(row[4])); - e.mountspeed = strtof(row[5], nullptr); + e.mountspeed = row[5] ? strtof(row[5], nullptr) : 0.75; e.notes = row[6] ? row[6] : ""; return e; @@ -286,7 +287,7 @@ public: e.race = static_cast(atoi(row[2])); e.gender = static_cast(atoi(row[3])); e.texture = static_cast(atoi(row[4])); - e.mountspeed = strtof(row[5], nullptr); + e.mountspeed = row[5] ? strtof(row[5], nullptr) : 0.75; e.notes = row[6] ? row[6] : ""; all_entries.push_back(e); @@ -317,7 +318,7 @@ public: e.race = static_cast(atoi(row[2])); e.gender = static_cast(atoi(row[3])); e.texture = static_cast(atoi(row[4])); - e.mountspeed = strtof(row[5], nullptr); + e.mountspeed = row[5] ? strtof(row[5], nullptr) : 0.75; e.notes = row[6] ? row[6] : ""; all_entries.push_back(e); @@ -377,6 +378,74 @@ 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 Horses &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.filename) + "'"); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.mountspeed)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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.filename) + "'"); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.mountspeed)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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_HORSES_REPOSITORY_H diff --git a/common/repositories/base/base_instance_list_player_repository.h b/common/repositories/base/base_instance_list_player_repository.h index 85e6fe012..28e487998 100644 --- a/common/repositories/base/base_instance_list_player_repository.h +++ b/common/repositories/base/base_instance_list_player_repository.h @@ -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_INSTANCE_LIST_PLAYER_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), instance_list_player_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { InstanceListPlayer e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { InstanceListPlayer e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { InstanceListPlayer e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 InstanceListPlayer &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.charid)); + + 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(std::to_string(e.charid)); + + 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_INSTANCE_LIST_PLAYER_REPOSITORY_H diff --git a/common/repositories/base/base_instance_list_repository.h b/common/repositories/base/base_instance_list_repository.h index dd82569ec..4e31b7e48 100644 --- a/common/repositories/base/base_instance_list_repository.h +++ b/common/repositories/base/base_instance_list_repository.h @@ -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_INSTANCE_LIST_REPOSITORY_H @@ -19,13 +19,14 @@ class BaseInstanceListRepository { public: struct InstanceList { - int32_t id; - uint32_t zone; - uint8_t version; - uint8_t is_global; - uint32_t start_time; - uint32_t duration; - uint8_t never_expires; + int32_t id; + uint32_t zone; + uint8_t version; + uint8_t is_global; + uint32_t start_time; + uint32_t duration; + uint8_t never_expires; + std::string notes; }; static std::string PrimaryKey() @@ -43,6 +44,7 @@ public: "start_time", "duration", "never_expires", + "notes", }; } @@ -56,6 +58,7 @@ public: "start_time", "duration", "never_expires", + "notes", }; } @@ -103,6 +106,7 @@ public: e.start_time = 0; e.duration = 0; e.never_expires = 0; + e.notes = ""; return e; } @@ -128,8 +132,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), instance_list_id ) ); @@ -139,12 +144,13 @@ public: InstanceList e{}; e.id = static_cast(atoi(row[0])); - e.zone = static_cast(strtoul(row[1], nullptr, 10)); - e.version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_global = static_cast(strtoul(row[3], nullptr, 10)); - e.start_time = static_cast(strtoul(row[4], nullptr, 10)); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); - e.never_expires = static_cast(strtoul(row[6], nullptr, 10)); + e.zone = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_global = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_time = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.never_expires = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.notes = row[7] ? row[7] : ""; return e; } @@ -184,6 +190,7 @@ public: v.push_back(columns[4] + " = " + std::to_string(e.start_time)); v.push_back(columns[5] + " = " + std::to_string(e.duration)); v.push_back(columns[6] + " = " + std::to_string(e.never_expires)); + v.push_back(columns[7] + " = '" + Strings::Escape(e.notes) + "'"); auto results = db.QueryDatabase( fmt::format( @@ -212,6 +219,7 @@ public: v.push_back(std::to_string(e.start_time)); v.push_back(std::to_string(e.duration)); v.push_back(std::to_string(e.never_expires)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); auto results = db.QueryDatabase( fmt::format( @@ -248,6 +256,7 @@ public: v.push_back(std::to_string(e.start_time)); v.push_back(std::to_string(e.duration)); v.push_back(std::to_string(e.never_expires)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } @@ -282,12 +291,13 @@ public: InstanceList e{}; e.id = static_cast(atoi(row[0])); - e.zone = static_cast(strtoul(row[1], nullptr, 10)); - e.version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_global = static_cast(strtoul(row[3], nullptr, 10)); - e.start_time = static_cast(strtoul(row[4], nullptr, 10)); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); - e.never_expires = static_cast(strtoul(row[6], nullptr, 10)); + e.zone = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_global = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_time = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.never_expires = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.notes = row[7] ? row[7] : ""; all_entries.push_back(e); } @@ -313,12 +323,13 @@ public: InstanceList e{}; e.id = static_cast(atoi(row[0])); - e.zone = static_cast(strtoul(row[1], nullptr, 10)); - e.version = static_cast(strtoul(row[2], nullptr, 10)); - e.is_global = static_cast(strtoul(row[3], nullptr, 10)); - e.start_time = static_cast(strtoul(row[4], nullptr, 10)); - e.duration = static_cast(strtoul(row[5], nullptr, 10)); - e.never_expires = static_cast(strtoul(row[6], nullptr, 10)); + e.zone = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.is_global = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.start_time = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.duration = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.never_expires = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.notes = row[7] ? row[7] : ""; all_entries.push_back(e); } @@ -377,6 +388,76 @@ 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 InstanceList &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zone)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.is_global)); + v.push_back(std::to_string(e.start_time)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.never_expires)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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(std::to_string(e.zone)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.is_global)); + v.push_back(std::to_string(e.start_time)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.never_expires)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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_INSTANCE_LIST_REPOSITORY_H diff --git a/common/repositories/base/base_inventory_repository.h b/common/repositories/base/base_inventory_repository.h index a3e0da3dd..57e6fce54 100644 --- a/common/repositories/base/base_inventory_repository.h +++ b/common/repositories/base/base_inventory_repository.h @@ -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_INVENTORY_REPOSITORY_H @@ -164,8 +164,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), inventory_id ) ); @@ -174,21 +175,21 @@ public: if (results.RowCount() == 1) { Inventory e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.slotid = static_cast(strtoul(row[1], nullptr, 10)); - e.itemid = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.color = static_cast(strtoul(row[4], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[9], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slotid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.itemid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.color = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.augslot1 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot2 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot3 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot4 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot5 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[10])); - e.instnodrop = static_cast(strtoul(row[11], nullptr, 10)); + e.instnodrop = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.custom_data = row[12] ? row[12] : ""; - e.ornamenticon = static_cast(strtoul(row[13], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[14], nullptr, 10)); + e.ornamenticon = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornamentidfile = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[15])); return e; @@ -354,21 +355,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Inventory e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.slotid = static_cast(strtoul(row[1], nullptr, 10)); - e.itemid = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.color = static_cast(strtoul(row[4], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[9], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slotid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.itemid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.color = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.augslot1 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot2 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot3 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot4 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot5 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[10])); - e.instnodrop = static_cast(strtoul(row[11], nullptr, 10)); + e.instnodrop = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.custom_data = row[12] ? row[12] : ""; - e.ornamenticon = static_cast(strtoul(row[13], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[14], nullptr, 10)); + e.ornamenticon = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornamentidfile = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[15])); all_entries.push_back(e); @@ -394,21 +395,21 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Inventory e{}; - e.charid = static_cast(strtoul(row[0], nullptr, 10)); - e.slotid = static_cast(strtoul(row[1], nullptr, 10)); - e.itemid = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.color = static_cast(strtoul(row[4], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[9], nullptr, 10)); + e.charid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slotid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.itemid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.color = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.augslot1 = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot2 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot3 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot4 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot5 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[10])); - e.instnodrop = static_cast(strtoul(row[11], nullptr, 10)); + e.instnodrop = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.custom_data = row[12] ? row[12] : ""; - e.ornamenticon = static_cast(strtoul(row[13], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[14], nullptr, 10)); + e.ornamenticon = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.ornamentidfile = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[15])); all_entries.push_back(e); @@ -468,6 +469,92 @@ 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 Inventory &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.slotid)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.color)); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + v.push_back(std::to_string(e.instnodrop)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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.charid)); + v.push_back(std::to_string(e.slotid)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.color)); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + v.push_back(std::to_string(e.instnodrop)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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_INVENTORY_REPOSITORY_H diff --git a/common/repositories/base/base_inventory_snapshots_repository.h b/common/repositories/base/base_inventory_snapshots_repository.h index 2ae90332f..a3d383705 100644 --- a/common/repositories/base/base_inventory_snapshots_repository.h +++ b/common/repositories/base/base_inventory_snapshots_repository.h @@ -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_INVENTORY_SNAPSHOTS_REPOSITORY_H @@ -168,8 +168,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), inventory_snapshots_id ) ); @@ -178,22 +179,22 @@ public: if (results.RowCount() == 1) { InventorySnapshots e{}; - e.time_index = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); - e.slotid = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); - e.charges = static_cast(strtoul(row[4], nullptr, 10)); - e.color = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.time_index = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slotid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.charges = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.color = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); - e.instnodrop = static_cast(strtoul(row[12], nullptr, 10)); + e.instnodrop = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.custom_data = row[13] ? row[13] : ""; - e.ornamenticon = static_cast(strtoul(row[14], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[15], nullptr, 10)); + e.ornamenticon = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ornamentidfile = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[16])); return e; @@ -362,22 +363,22 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { InventorySnapshots e{}; - e.time_index = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); - e.slotid = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); - e.charges = static_cast(strtoul(row[4], nullptr, 10)); - e.color = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.time_index = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slotid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.charges = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.color = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); - e.instnodrop = static_cast(strtoul(row[12], nullptr, 10)); + e.instnodrop = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.custom_data = row[13] ? row[13] : ""; - e.ornamenticon = static_cast(strtoul(row[14], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[15], nullptr, 10)); + e.ornamenticon = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ornamentidfile = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[16])); all_entries.push_back(e); @@ -403,22 +404,22 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { InventorySnapshots e{}; - e.time_index = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); - e.slotid = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); - e.charges = static_cast(strtoul(row[4], nullptr, 10)); - e.color = static_cast(strtoul(row[5], nullptr, 10)); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.time_index = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.slotid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.charges = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.color = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); - e.instnodrop = static_cast(strtoul(row[12], nullptr, 10)); + e.instnodrop = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.custom_data = row[13] ? row[13] : ""; - e.ornamenticon = static_cast(strtoul(row[14], nullptr, 10)); - e.ornamentidfile = static_cast(strtoul(row[15], nullptr, 10)); + e.ornamenticon = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.ornamentidfile = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; e.ornament_hero_model = static_cast(atoi(row[16])); all_entries.push_back(e); @@ -478,6 +479,94 @@ 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 InventorySnapshots &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.time_index)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.slotid)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.color)); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + v.push_back(std::to_string(e.instnodrop)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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.time_index)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.slotid)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.color)); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + v.push_back(std::to_string(e.instnodrop)); + v.push_back("'" + Strings::Escape(e.custom_data) + "'"); + v.push_back(std::to_string(e.ornamenticon)); + v.push_back(std::to_string(e.ornamentidfile)); + v.push_back(std::to_string(e.ornament_hero_model)); + + 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_INVENTORY_SNAPSHOTS_REPOSITORY_H diff --git a/common/repositories/base/base_ip_exemptions_repository.h b/common/repositories/base/base_ip_exemptions_repository.h index f76e8c7a4..ad85ff18a 100644 --- a/common/repositories/base/base_ip_exemptions_repository.h +++ b/common/repositories/base/base_ip_exemptions_repository.h @@ -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_IP_EXEMPTIONS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), ip_exemptions_id ) ); @@ -337,6 +338,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 IpExemptions &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.exemption_id)); + v.push_back("'" + Strings::Escape(e.exemption_ip) + "'"); + v.push_back(std::to_string(e.exemption_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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.exemption_id)); + v.push_back("'" + Strings::Escape(e.exemption_ip) + "'"); + v.push_back(std::to_string(e.exemption_amount)); + + 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_IP_EXEMPTIONS_REPOSITORY_H diff --git a/common/repositories/base/base_item_tick_repository.h b/common/repositories/base/base_item_tick_repository.h index 08b9ded48..6f4954f04 100644 --- a/common/repositories/base/base_item_tick_repository.h +++ b/common/repositories/base/base_item_tick_repository.h @@ -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_ITEM_TICK_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), item_tick_id ) ); @@ -367,6 +368,72 @@ 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 ItemTick &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.it_itemid)); + v.push_back(std::to_string(e.it_chance)); + v.push_back(std::to_string(e.it_level)); + v.push_back(std::to_string(e.it_id)); + v.push_back("'" + Strings::Escape(e.it_qglobal) + "'"); + v.push_back(std::to_string(e.it_bagslot)); + + 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.it_itemid)); + v.push_back(std::to_string(e.it_chance)); + v.push_back(std::to_string(e.it_level)); + v.push_back(std::to_string(e.it_id)); + v.push_back("'" + Strings::Escape(e.it_qglobal) + "'"); + v.push_back(std::to_string(e.it_bagslot)); + + 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_ITEM_TICK_REPOSITORY_H diff --git a/common/repositories/base/base_items_repository.h b/common/repositories/base/base_items_repository.h index dade672d8..dfbbfda74 100644 --- a/common/repositories/base/base_items_repository.h +++ b/common/repositories/base/base_items_repository.h @@ -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_ITEMS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseItemsRepository { public: struct Items { @@ -1261,7 +1260,7 @@ public: e.acha = static_cast(atoi(row[6])); e.adex = static_cast(atoi(row[7])); e.aint = static_cast(atoi(row[8])); - e.artifactflag = static_cast(strtoul(row[9], nullptr, 10)); + e.artifactflag = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.asta = static_cast(atoi(row[10])); e.astr = static_cast(atoi(row[11])); e.attack = static_cast(atoi(row[12])); @@ -1297,7 +1296,7 @@ public: e.charmfile = row[42] ? row[42] : ""; e.charmfileid = row[43] ? row[43] : ""; e.classes = static_cast(atoi(row[44])); - e.color = static_cast(strtoul(row[45], nullptr, 10)); + e.color = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; e.combateffects = row[46] ? row[46] : ""; e.extradmgskill = static_cast(atoi(row[47])); e.extradmgamt = static_cast(atoi(row[48])); @@ -1307,7 +1306,7 @@ public: e.damageshield = static_cast(atoi(row[52])); e.deity = static_cast(atoi(row[53])); e.delay = static_cast(atoi(row[54])); - e.augdistiller = static_cast(strtoul(row[55], nullptr, 10)); + e.augdistiller = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; e.dotshielding = static_cast(atoi(row[56])); e.dr = static_cast(atoi(row[57])); e.clicktype = static_cast(atoi(row[58])); @@ -1351,7 +1350,7 @@ public: e.mr = static_cast(atoi(row[96])); e.nodrop = static_cast(atoi(row[97])); e.norent = static_cast(atoi(row[98])); - e.pendingloreflag = static_cast(strtoul(row[99], nullptr, 10)); + e.pendingloreflag = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); @@ -1359,7 +1358,7 @@ public: e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); - e.sellrate = strtof(row[107], nullptr); + e.sellrate = row[107] ? strtof(row[107], nullptr) : 0; e.shielding = static_cast(atoi(row[108])); e.size = static_cast(atoi(row[109])); e.skillmodtype = static_cast(atoi(row[110])); @@ -1369,7 +1368,7 @@ public: e.spellshield = static_cast(atoi(row[114])); e.strikethrough = static_cast(atoi(row[115])); e.stunresist = static_cast(atoi(row[116])); - e.summonedflag = static_cast(strtoul(row[117], nullptr, 10)); + e.summonedflag = row[117] ? static_cast(strtoul(row[117], nullptr, 10)) : 0; e.tradeskills = static_cast(atoi(row[118])); e.favor = static_cast(atoi(row[119])); e.weight = static_cast(atoi(row[120])); @@ -1459,7 +1458,7 @@ public: e.focusunk5 = static_cast(atoi(row[204])); e.focusunk6 = row[205] ? row[205] : ""; e.focusunk7 = static_cast(atoi(row[206])); - e.scrollunk1 = static_cast(strtoul(row[207], nullptr, 10)); + e.scrollunk1 = row[207] ? static_cast(strtoul(row[207], nullptr, 10)) : 0; e.scrollunk2 = static_cast(atoi(row[208])); e.scrollunk3 = static_cast(atoi(row[209])); e.scrollunk4 = static_cast(atoi(row[210])); @@ -2517,7 +2516,7 @@ public: e.acha = static_cast(atoi(row[6])); e.adex = static_cast(atoi(row[7])); e.aint = static_cast(atoi(row[8])); - e.artifactflag = static_cast(strtoul(row[9], nullptr, 10)); + e.artifactflag = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.asta = static_cast(atoi(row[10])); e.astr = static_cast(atoi(row[11])); e.attack = static_cast(atoi(row[12])); @@ -2553,7 +2552,7 @@ public: e.charmfile = row[42] ? row[42] : ""; e.charmfileid = row[43] ? row[43] : ""; e.classes = static_cast(atoi(row[44])); - e.color = static_cast(strtoul(row[45], nullptr, 10)); + e.color = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; e.combateffects = row[46] ? row[46] : ""; e.extradmgskill = static_cast(atoi(row[47])); e.extradmgamt = static_cast(atoi(row[48])); @@ -2563,7 +2562,7 @@ public: e.damageshield = static_cast(atoi(row[52])); e.deity = static_cast(atoi(row[53])); e.delay = static_cast(atoi(row[54])); - e.augdistiller = static_cast(strtoul(row[55], nullptr, 10)); + e.augdistiller = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; e.dotshielding = static_cast(atoi(row[56])); e.dr = static_cast(atoi(row[57])); e.clicktype = static_cast(atoi(row[58])); @@ -2607,7 +2606,7 @@ public: e.mr = static_cast(atoi(row[96])); e.nodrop = static_cast(atoi(row[97])); e.norent = static_cast(atoi(row[98])); - e.pendingloreflag = static_cast(strtoul(row[99], nullptr, 10)); + e.pendingloreflag = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); @@ -2615,7 +2614,7 @@ public: e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); - e.sellrate = strtof(row[107], nullptr); + e.sellrate = row[107] ? strtof(row[107], nullptr) : 0; e.shielding = static_cast(atoi(row[108])); e.size = static_cast(atoi(row[109])); e.skillmodtype = static_cast(atoi(row[110])); @@ -2625,7 +2624,7 @@ public: e.spellshield = static_cast(atoi(row[114])); e.strikethrough = static_cast(atoi(row[115])); e.stunresist = static_cast(atoi(row[116])); - e.summonedflag = static_cast(strtoul(row[117], nullptr, 10)); + e.summonedflag = row[117] ? static_cast(strtoul(row[117], nullptr, 10)) : 0; e.tradeskills = static_cast(atoi(row[118])); e.favor = static_cast(atoi(row[119])); e.weight = static_cast(atoi(row[120])); @@ -2715,7 +2714,7 @@ public: e.focusunk5 = static_cast(atoi(row[204])); e.focusunk6 = row[205] ? row[205] : ""; e.focusunk7 = static_cast(atoi(row[206])); - e.scrollunk1 = static_cast(strtoul(row[207], nullptr, 10)); + e.scrollunk1 = row[207] ? static_cast(strtoul(row[207], nullptr, 10)) : 0; e.scrollunk2 = static_cast(atoi(row[208])); e.scrollunk3 = static_cast(atoi(row[209])); e.scrollunk4 = static_cast(atoi(row[210])); @@ -2826,7 +2825,7 @@ public: e.acha = static_cast(atoi(row[6])); e.adex = static_cast(atoi(row[7])); e.aint = static_cast(atoi(row[8])); - e.artifactflag = static_cast(strtoul(row[9], nullptr, 10)); + e.artifactflag = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.asta = static_cast(atoi(row[10])); e.astr = static_cast(atoi(row[11])); e.attack = static_cast(atoi(row[12])); @@ -2862,7 +2861,7 @@ public: e.charmfile = row[42] ? row[42] : ""; e.charmfileid = row[43] ? row[43] : ""; e.classes = static_cast(atoi(row[44])); - e.color = static_cast(strtoul(row[45], nullptr, 10)); + e.color = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; e.combateffects = row[46] ? row[46] : ""; e.extradmgskill = static_cast(atoi(row[47])); e.extradmgamt = static_cast(atoi(row[48])); @@ -2872,7 +2871,7 @@ public: e.damageshield = static_cast(atoi(row[52])); e.deity = static_cast(atoi(row[53])); e.delay = static_cast(atoi(row[54])); - e.augdistiller = static_cast(strtoul(row[55], nullptr, 10)); + e.augdistiller = row[55] ? static_cast(strtoul(row[55], nullptr, 10)) : 0; e.dotshielding = static_cast(atoi(row[56])); e.dr = static_cast(atoi(row[57])); e.clicktype = static_cast(atoi(row[58])); @@ -2916,7 +2915,7 @@ public: e.mr = static_cast(atoi(row[96])); e.nodrop = static_cast(atoi(row[97])); e.norent = static_cast(atoi(row[98])); - e.pendingloreflag = static_cast(strtoul(row[99], nullptr, 10)); + e.pendingloreflag = row[99] ? static_cast(strtoul(row[99], nullptr, 10)) : 0; e.pr = static_cast(atoi(row[100])); e.procrate = static_cast(atoi(row[101])); e.races = static_cast(atoi(row[102])); @@ -2924,7 +2923,7 @@ public: e.reclevel = static_cast(atoi(row[104])); e.recskill = static_cast(atoi(row[105])); e.reqlevel = static_cast(atoi(row[106])); - e.sellrate = strtof(row[107], nullptr); + e.sellrate = row[107] ? strtof(row[107], nullptr) : 0; e.shielding = static_cast(atoi(row[108])); e.size = static_cast(atoi(row[109])); e.skillmodtype = static_cast(atoi(row[110])); @@ -2934,7 +2933,7 @@ public: e.spellshield = static_cast(atoi(row[114])); e.strikethrough = static_cast(atoi(row[115])); e.stunresist = static_cast(atoi(row[116])); - e.summonedflag = static_cast(strtoul(row[117], nullptr, 10)); + e.summonedflag = row[117] ? static_cast(strtoul(row[117], nullptr, 10)) : 0; e.tradeskills = static_cast(atoi(row[118])); e.favor = static_cast(atoi(row[119])); e.weight = static_cast(atoi(row[120])); @@ -3024,7 +3023,7 @@ public: e.focusunk5 = static_cast(atoi(row[204])); e.focusunk6 = row[205] ? row[205] : ""; e.focusunk7 = static_cast(atoi(row[206])); - e.scrollunk1 = static_cast(strtoul(row[207], nullptr, 10)); + e.scrollunk1 = row[207] ? static_cast(strtoul(row[207], nullptr, 10)) : 0; e.scrollunk2 = static_cast(atoi(row[208])); e.scrollunk3 = static_cast(atoi(row[209])); e.scrollunk4 = static_cast(atoi(row[210])); @@ -3160,6 +3159,630 @@ 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 Items &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.minstatus)); + v.push_back("'" + Strings::Escape(e.Name) + "'"); + v.push_back(std::to_string(e.aagi)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.acha)); + v.push_back(std::to_string(e.adex)); + v.push_back(std::to_string(e.aint)); + v.push_back(std::to_string(e.artifactflag)); + v.push_back(std::to_string(e.asta)); + v.push_back(std::to_string(e.astr)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.augrestrict)); + v.push_back(std::to_string(e.augslot1type)); + v.push_back(std::to_string(e.augslot1visible)); + v.push_back(std::to_string(e.augslot2type)); + v.push_back(std::to_string(e.augslot2visible)); + v.push_back(std::to_string(e.augslot3type)); + v.push_back(std::to_string(e.augslot3visible)); + v.push_back(std::to_string(e.augslot4type)); + v.push_back(std::to_string(e.augslot4visible)); + v.push_back(std::to_string(e.augslot5type)); + v.push_back(std::to_string(e.augslot5visible)); + v.push_back(std::to_string(e.augslot6type)); + v.push_back(std::to_string(e.augslot6visible)); + v.push_back(std::to_string(e.augtype)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.awis)); + v.push_back(std::to_string(e.bagsize)); + v.push_back(std::to_string(e.bagslots)); + v.push_back(std::to_string(e.bagtype)); + v.push_back(std::to_string(e.bagwr)); + v.push_back(std::to_string(e.banedmgamt)); + v.push_back(std::to_string(e.banedmgraceamt)); + v.push_back(std::to_string(e.banedmgbody)); + v.push_back(std::to_string(e.banedmgrace)); + v.push_back(std::to_string(e.bardtype)); + v.push_back(std::to_string(e.bardvalue)); + v.push_back(std::to_string(e.book)); + v.push_back(std::to_string(e.casttime)); + v.push_back(std::to_string(e.casttime_)); + v.push_back("'" + Strings::Escape(e.charmfile) + "'"); + v.push_back("'" + Strings::Escape(e.charmfileid) + "'"); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.color)); + v.push_back("'" + Strings::Escape(e.combateffects) + "'"); + v.push_back(std::to_string(e.extradmgskill)); + v.push_back(std::to_string(e.extradmgamt)); + v.push_back(std::to_string(e.price)); + v.push_back(std::to_string(e.cr)); + v.push_back(std::to_string(e.damage)); + v.push_back(std::to_string(e.damageshield)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.delay)); + v.push_back(std::to_string(e.augdistiller)); + v.push_back(std::to_string(e.dotshielding)); + v.push_back(std::to_string(e.dr)); + v.push_back(std::to_string(e.clicktype)); + v.push_back(std::to_string(e.clicklevel2)); + v.push_back(std::to_string(e.elemdmgtype)); + v.push_back(std::to_string(e.elemdmgamt)); + v.push_back(std::to_string(e.endur)); + v.push_back(std::to_string(e.factionamt1)); + v.push_back(std::to_string(e.factionamt2)); + v.push_back(std::to_string(e.factionamt3)); + v.push_back(std::to_string(e.factionamt4)); + v.push_back(std::to_string(e.factionmod1)); + v.push_back(std::to_string(e.factionmod2)); + v.push_back(std::to_string(e.factionmod3)); + v.push_back(std::to_string(e.factionmod4)); + v.push_back("'" + Strings::Escape(e.filename) + "'"); + v.push_back(std::to_string(e.focuseffect)); + v.push_back(std::to_string(e.fr)); + v.push_back(std::to_string(e.fvnodrop)); + v.push_back(std::to_string(e.haste)); + v.push_back(std::to_string(e.clicklevel)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.regen)); + v.push_back(std::to_string(e.icon)); + v.push_back("'" + Strings::Escape(e.idfile) + "'"); + v.push_back(std::to_string(e.itemclass)); + v.push_back(std::to_string(e.itemtype)); + v.push_back(std::to_string(e.ldonprice)); + v.push_back(std::to_string(e.ldontheme)); + v.push_back(std::to_string(e.ldonsold)); + v.push_back(std::to_string(e.light)); + v.push_back("'" + Strings::Escape(e.lore) + "'"); + v.push_back(std::to_string(e.loregroup)); + v.push_back(std::to_string(e.magic)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.manaregen)); + v.push_back(std::to_string(e.enduranceregen)); + v.push_back(std::to_string(e.material)); + v.push_back(std::to_string(e.herosforgemodel)); + v.push_back(std::to_string(e.maxcharges)); + v.push_back(std::to_string(e.mr)); + v.push_back(std::to_string(e.nodrop)); + v.push_back(std::to_string(e.norent)); + v.push_back(std::to_string(e.pendingloreflag)); + v.push_back(std::to_string(e.pr)); + v.push_back(std::to_string(e.procrate)); + v.push_back(std::to_string(e.races)); + v.push_back(std::to_string(e.range_)); + v.push_back(std::to_string(e.reclevel)); + v.push_back(std::to_string(e.recskill)); + v.push_back(std::to_string(e.reqlevel)); + v.push_back(std::to_string(e.sellrate)); + v.push_back(std::to_string(e.shielding)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.skillmodtype)); + v.push_back(std::to_string(e.skillmodvalue)); + v.push_back(std::to_string(e.slots)); + v.push_back(std::to_string(e.clickeffect)); + v.push_back(std::to_string(e.spellshield)); + v.push_back(std::to_string(e.strikethrough)); + v.push_back(std::to_string(e.stunresist)); + v.push_back(std::to_string(e.summonedflag)); + v.push_back(std::to_string(e.tradeskills)); + v.push_back(std::to_string(e.favor)); + v.push_back(std::to_string(e.weight)); + v.push_back(std::to_string(e.UNK012)); + v.push_back(std::to_string(e.UNK013)); + v.push_back(std::to_string(e.benefitflag)); + v.push_back(std::to_string(e.UNK054)); + v.push_back(std::to_string(e.UNK059)); + v.push_back(std::to_string(e.booktype)); + v.push_back(std::to_string(e.recastdelay)); + v.push_back(std::to_string(e.recasttype)); + v.push_back(std::to_string(e.guildfavor)); + v.push_back(std::to_string(e.UNK123)); + v.push_back(std::to_string(e.UNK124)); + v.push_back(std::to_string(e.attuneable)); + v.push_back(std::to_string(e.nopet)); + v.push_back("FROM_UNIXTIME(" + (e.updated > 0 ? std::to_string(e.updated) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.UNK127)); + v.push_back(std::to_string(e.pointtype)); + v.push_back(std::to_string(e.potionbelt)); + v.push_back(std::to_string(e.potionbeltslots)); + v.push_back(std::to_string(e.stacksize)); + v.push_back(std::to_string(e.notransfer)); + v.push_back(std::to_string(e.stackable)); + v.push_back("'" + Strings::Escape(e.UNK134) + "'"); + v.push_back(std::to_string(e.UNK137)); + v.push_back(std::to_string(e.proceffect)); + v.push_back(std::to_string(e.proctype)); + v.push_back(std::to_string(e.proclevel2)); + v.push_back(std::to_string(e.proclevel)); + v.push_back(std::to_string(e.UNK142)); + v.push_back(std::to_string(e.worneffect)); + v.push_back(std::to_string(e.worntype)); + v.push_back(std::to_string(e.wornlevel2)); + v.push_back(std::to_string(e.wornlevel)); + v.push_back(std::to_string(e.UNK147)); + v.push_back(std::to_string(e.focustype)); + v.push_back(std::to_string(e.focuslevel2)); + v.push_back(std::to_string(e.focuslevel)); + v.push_back(std::to_string(e.UNK152)); + v.push_back(std::to_string(e.scrolleffect)); + v.push_back(std::to_string(e.scrolltype)); + v.push_back(std::to_string(e.scrolllevel2)); + v.push_back(std::to_string(e.scrolllevel)); + v.push_back(std::to_string(e.UNK157)); + v.push_back("FROM_UNIXTIME(" + (e.serialized > 0 ? std::to_string(e.serialized) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.verified > 0 ? std::to_string(e.verified) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.serialization) + "'"); + v.push_back("'" + Strings::Escape(e.source) + "'"); + v.push_back(std::to_string(e.UNK033)); + v.push_back("'" + Strings::Escape(e.lorefile) + "'"); + v.push_back(std::to_string(e.UNK014)); + v.push_back(std::to_string(e.svcorruption)); + v.push_back(std::to_string(e.skillmodmax)); + v.push_back(std::to_string(e.UNK060)); + v.push_back(std::to_string(e.augslot1unk2)); + v.push_back(std::to_string(e.augslot2unk2)); + v.push_back(std::to_string(e.augslot3unk2)); + v.push_back(std::to_string(e.augslot4unk2)); + v.push_back(std::to_string(e.augslot5unk2)); + v.push_back(std::to_string(e.augslot6unk2)); + v.push_back(std::to_string(e.UNK120)); + v.push_back(std::to_string(e.UNK121)); + v.push_back(std::to_string(e.questitemflag)); + v.push_back("'" + Strings::Escape(e.UNK132) + "'"); + v.push_back(std::to_string(e.clickunk5)); + v.push_back("'" + Strings::Escape(e.clickunk6) + "'"); + v.push_back(std::to_string(e.clickunk7)); + v.push_back(std::to_string(e.procunk1)); + v.push_back(std::to_string(e.procunk2)); + v.push_back(std::to_string(e.procunk3)); + v.push_back(std::to_string(e.procunk4)); + v.push_back("'" + Strings::Escape(e.procunk6) + "'"); + v.push_back(std::to_string(e.procunk7)); + v.push_back(std::to_string(e.wornunk1)); + v.push_back(std::to_string(e.wornunk2)); + v.push_back(std::to_string(e.wornunk3)); + v.push_back(std::to_string(e.wornunk4)); + v.push_back(std::to_string(e.wornunk5)); + v.push_back("'" + Strings::Escape(e.wornunk6) + "'"); + v.push_back(std::to_string(e.wornunk7)); + v.push_back(std::to_string(e.focusunk1)); + v.push_back(std::to_string(e.focusunk2)); + v.push_back(std::to_string(e.focusunk3)); + v.push_back(std::to_string(e.focusunk4)); + v.push_back(std::to_string(e.focusunk5)); + v.push_back("'" + Strings::Escape(e.focusunk6) + "'"); + v.push_back(std::to_string(e.focusunk7)); + v.push_back(std::to_string(e.scrollunk1)); + v.push_back(std::to_string(e.scrollunk2)); + v.push_back(std::to_string(e.scrollunk3)); + v.push_back(std::to_string(e.scrollunk4)); + v.push_back(std::to_string(e.scrollunk5)); + v.push_back("'" + Strings::Escape(e.scrollunk6) + "'"); + v.push_back(std::to_string(e.scrollunk7)); + v.push_back(std::to_string(e.UNK193)); + v.push_back(std::to_string(e.purity)); + v.push_back(std::to_string(e.evoitem)); + v.push_back(std::to_string(e.evoid)); + v.push_back(std::to_string(e.evolvinglevel)); + v.push_back(std::to_string(e.evomax)); + v.push_back("'" + Strings::Escape(e.clickname) + "'"); + v.push_back("'" + Strings::Escape(e.procname) + "'"); + v.push_back("'" + Strings::Escape(e.wornname) + "'"); + v.push_back("'" + Strings::Escape(e.focusname) + "'"); + v.push_back("'" + Strings::Escape(e.scrollname) + "'"); + v.push_back(std::to_string(e.dsmitigation)); + v.push_back(std::to_string(e.heroic_str)); + v.push_back(std::to_string(e.heroic_int)); + v.push_back(std::to_string(e.heroic_wis)); + v.push_back(std::to_string(e.heroic_agi)); + v.push_back(std::to_string(e.heroic_dex)); + v.push_back(std::to_string(e.heroic_sta)); + v.push_back(std::to_string(e.heroic_cha)); + v.push_back(std::to_string(e.heroic_pr)); + v.push_back(std::to_string(e.heroic_dr)); + v.push_back(std::to_string(e.heroic_fr)); + v.push_back(std::to_string(e.heroic_cr)); + v.push_back(std::to_string(e.heroic_mr)); + v.push_back(std::to_string(e.heroic_svcorrup)); + v.push_back(std::to_string(e.healamt)); + v.push_back(std::to_string(e.spelldmg)); + v.push_back(std::to_string(e.clairvoyance)); + v.push_back(std::to_string(e.backstabdmg)); + v.push_back("'" + Strings::Escape(e.created) + "'"); + v.push_back(std::to_string(e.elitematerial)); + v.push_back(std::to_string(e.ldonsellbackrate)); + v.push_back(std::to_string(e.scriptfileid)); + v.push_back(std::to_string(e.expendablearrow)); + v.push_back(std::to_string(e.powersourcecapacity)); + v.push_back(std::to_string(e.bardeffect)); + v.push_back(std::to_string(e.bardeffecttype)); + v.push_back(std::to_string(e.bardlevel2)); + v.push_back(std::to_string(e.bardlevel)); + v.push_back(std::to_string(e.bardunk1)); + v.push_back(std::to_string(e.bardunk2)); + v.push_back(std::to_string(e.bardunk3)); + v.push_back(std::to_string(e.bardunk4)); + v.push_back(std::to_string(e.bardunk5)); + v.push_back("'" + Strings::Escape(e.bardname) + "'"); + v.push_back(std::to_string(e.bardunk7)); + v.push_back(std::to_string(e.UNK214)); + v.push_back(std::to_string(e.subtype)); + v.push_back(std::to_string(e.UNK220)); + v.push_back(std::to_string(e.UNK221)); + v.push_back(std::to_string(e.heirloom)); + v.push_back(std::to_string(e.UNK223)); + v.push_back(std::to_string(e.UNK224)); + v.push_back(std::to_string(e.UNK225)); + v.push_back(std::to_string(e.UNK226)); + v.push_back(std::to_string(e.UNK227)); + v.push_back(std::to_string(e.UNK228)); + v.push_back(std::to_string(e.UNK229)); + v.push_back(std::to_string(e.UNK230)); + v.push_back(std::to_string(e.UNK231)); + v.push_back(std::to_string(e.UNK232)); + v.push_back(std::to_string(e.UNK233)); + v.push_back(std::to_string(e.UNK234)); + v.push_back(std::to_string(e.placeable)); + v.push_back(std::to_string(e.UNK236)); + v.push_back(std::to_string(e.UNK237)); + v.push_back(std::to_string(e.UNK238)); + v.push_back(std::to_string(e.UNK239)); + v.push_back(std::to_string(e.UNK240)); + v.push_back(std::to_string(e.UNK241)); + v.push_back(std::to_string(e.epicitem)); + + 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(std::to_string(e.minstatus)); + v.push_back("'" + Strings::Escape(e.Name) + "'"); + v.push_back(std::to_string(e.aagi)); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.acha)); + v.push_back(std::to_string(e.adex)); + v.push_back(std::to_string(e.aint)); + v.push_back(std::to_string(e.artifactflag)); + v.push_back(std::to_string(e.asta)); + v.push_back(std::to_string(e.astr)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.augrestrict)); + v.push_back(std::to_string(e.augslot1type)); + v.push_back(std::to_string(e.augslot1visible)); + v.push_back(std::to_string(e.augslot2type)); + v.push_back(std::to_string(e.augslot2visible)); + v.push_back(std::to_string(e.augslot3type)); + v.push_back(std::to_string(e.augslot3visible)); + v.push_back(std::to_string(e.augslot4type)); + v.push_back(std::to_string(e.augslot4visible)); + v.push_back(std::to_string(e.augslot5type)); + v.push_back(std::to_string(e.augslot5visible)); + v.push_back(std::to_string(e.augslot6type)); + v.push_back(std::to_string(e.augslot6visible)); + v.push_back(std::to_string(e.augtype)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.awis)); + v.push_back(std::to_string(e.bagsize)); + v.push_back(std::to_string(e.bagslots)); + v.push_back(std::to_string(e.bagtype)); + v.push_back(std::to_string(e.bagwr)); + v.push_back(std::to_string(e.banedmgamt)); + v.push_back(std::to_string(e.banedmgraceamt)); + v.push_back(std::to_string(e.banedmgbody)); + v.push_back(std::to_string(e.banedmgrace)); + v.push_back(std::to_string(e.bardtype)); + v.push_back(std::to_string(e.bardvalue)); + v.push_back(std::to_string(e.book)); + v.push_back(std::to_string(e.casttime)); + v.push_back(std::to_string(e.casttime_)); + v.push_back("'" + Strings::Escape(e.charmfile) + "'"); + v.push_back("'" + Strings::Escape(e.charmfileid) + "'"); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.color)); + v.push_back("'" + Strings::Escape(e.combateffects) + "'"); + v.push_back(std::to_string(e.extradmgskill)); + v.push_back(std::to_string(e.extradmgamt)); + v.push_back(std::to_string(e.price)); + v.push_back(std::to_string(e.cr)); + v.push_back(std::to_string(e.damage)); + v.push_back(std::to_string(e.damageshield)); + v.push_back(std::to_string(e.deity)); + v.push_back(std::to_string(e.delay)); + v.push_back(std::to_string(e.augdistiller)); + v.push_back(std::to_string(e.dotshielding)); + v.push_back(std::to_string(e.dr)); + v.push_back(std::to_string(e.clicktype)); + v.push_back(std::to_string(e.clicklevel2)); + v.push_back(std::to_string(e.elemdmgtype)); + v.push_back(std::to_string(e.elemdmgamt)); + v.push_back(std::to_string(e.endur)); + v.push_back(std::to_string(e.factionamt1)); + v.push_back(std::to_string(e.factionamt2)); + v.push_back(std::to_string(e.factionamt3)); + v.push_back(std::to_string(e.factionamt4)); + v.push_back(std::to_string(e.factionmod1)); + v.push_back(std::to_string(e.factionmod2)); + v.push_back(std::to_string(e.factionmod3)); + v.push_back(std::to_string(e.factionmod4)); + v.push_back("'" + Strings::Escape(e.filename) + "'"); + v.push_back(std::to_string(e.focuseffect)); + v.push_back(std::to_string(e.fr)); + v.push_back(std::to_string(e.fvnodrop)); + v.push_back(std::to_string(e.haste)); + v.push_back(std::to_string(e.clicklevel)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.regen)); + v.push_back(std::to_string(e.icon)); + v.push_back("'" + Strings::Escape(e.idfile) + "'"); + v.push_back(std::to_string(e.itemclass)); + v.push_back(std::to_string(e.itemtype)); + v.push_back(std::to_string(e.ldonprice)); + v.push_back(std::to_string(e.ldontheme)); + v.push_back(std::to_string(e.ldonsold)); + v.push_back(std::to_string(e.light)); + v.push_back("'" + Strings::Escape(e.lore) + "'"); + v.push_back(std::to_string(e.loregroup)); + v.push_back(std::to_string(e.magic)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.manaregen)); + v.push_back(std::to_string(e.enduranceregen)); + v.push_back(std::to_string(e.material)); + v.push_back(std::to_string(e.herosforgemodel)); + v.push_back(std::to_string(e.maxcharges)); + v.push_back(std::to_string(e.mr)); + v.push_back(std::to_string(e.nodrop)); + v.push_back(std::to_string(e.norent)); + v.push_back(std::to_string(e.pendingloreflag)); + v.push_back(std::to_string(e.pr)); + v.push_back(std::to_string(e.procrate)); + v.push_back(std::to_string(e.races)); + v.push_back(std::to_string(e.range_)); + v.push_back(std::to_string(e.reclevel)); + v.push_back(std::to_string(e.recskill)); + v.push_back(std::to_string(e.reqlevel)); + v.push_back(std::to_string(e.sellrate)); + v.push_back(std::to_string(e.shielding)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.skillmodtype)); + v.push_back(std::to_string(e.skillmodvalue)); + v.push_back(std::to_string(e.slots)); + v.push_back(std::to_string(e.clickeffect)); + v.push_back(std::to_string(e.spellshield)); + v.push_back(std::to_string(e.strikethrough)); + v.push_back(std::to_string(e.stunresist)); + v.push_back(std::to_string(e.summonedflag)); + v.push_back(std::to_string(e.tradeskills)); + v.push_back(std::to_string(e.favor)); + v.push_back(std::to_string(e.weight)); + v.push_back(std::to_string(e.UNK012)); + v.push_back(std::to_string(e.UNK013)); + v.push_back(std::to_string(e.benefitflag)); + v.push_back(std::to_string(e.UNK054)); + v.push_back(std::to_string(e.UNK059)); + v.push_back(std::to_string(e.booktype)); + v.push_back(std::to_string(e.recastdelay)); + v.push_back(std::to_string(e.recasttype)); + v.push_back(std::to_string(e.guildfavor)); + v.push_back(std::to_string(e.UNK123)); + v.push_back(std::to_string(e.UNK124)); + v.push_back(std::to_string(e.attuneable)); + v.push_back(std::to_string(e.nopet)); + v.push_back("FROM_UNIXTIME(" + (e.updated > 0 ? std::to_string(e.updated) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.UNK127)); + v.push_back(std::to_string(e.pointtype)); + v.push_back(std::to_string(e.potionbelt)); + v.push_back(std::to_string(e.potionbeltslots)); + v.push_back(std::to_string(e.stacksize)); + v.push_back(std::to_string(e.notransfer)); + v.push_back(std::to_string(e.stackable)); + v.push_back("'" + Strings::Escape(e.UNK134) + "'"); + v.push_back(std::to_string(e.UNK137)); + v.push_back(std::to_string(e.proceffect)); + v.push_back(std::to_string(e.proctype)); + v.push_back(std::to_string(e.proclevel2)); + v.push_back(std::to_string(e.proclevel)); + v.push_back(std::to_string(e.UNK142)); + v.push_back(std::to_string(e.worneffect)); + v.push_back(std::to_string(e.worntype)); + v.push_back(std::to_string(e.wornlevel2)); + v.push_back(std::to_string(e.wornlevel)); + v.push_back(std::to_string(e.UNK147)); + v.push_back(std::to_string(e.focustype)); + v.push_back(std::to_string(e.focuslevel2)); + v.push_back(std::to_string(e.focuslevel)); + v.push_back(std::to_string(e.UNK152)); + v.push_back(std::to_string(e.scrolleffect)); + v.push_back(std::to_string(e.scrolltype)); + v.push_back(std::to_string(e.scrolllevel2)); + v.push_back(std::to_string(e.scrolllevel)); + v.push_back(std::to_string(e.UNK157)); + v.push_back("FROM_UNIXTIME(" + (e.serialized > 0 ? std::to_string(e.serialized) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.verified > 0 ? std::to_string(e.verified) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.serialization) + "'"); + v.push_back("'" + Strings::Escape(e.source) + "'"); + v.push_back(std::to_string(e.UNK033)); + v.push_back("'" + Strings::Escape(e.lorefile) + "'"); + v.push_back(std::to_string(e.UNK014)); + v.push_back(std::to_string(e.svcorruption)); + v.push_back(std::to_string(e.skillmodmax)); + v.push_back(std::to_string(e.UNK060)); + v.push_back(std::to_string(e.augslot1unk2)); + v.push_back(std::to_string(e.augslot2unk2)); + v.push_back(std::to_string(e.augslot3unk2)); + v.push_back(std::to_string(e.augslot4unk2)); + v.push_back(std::to_string(e.augslot5unk2)); + v.push_back(std::to_string(e.augslot6unk2)); + v.push_back(std::to_string(e.UNK120)); + v.push_back(std::to_string(e.UNK121)); + v.push_back(std::to_string(e.questitemflag)); + v.push_back("'" + Strings::Escape(e.UNK132) + "'"); + v.push_back(std::to_string(e.clickunk5)); + v.push_back("'" + Strings::Escape(e.clickunk6) + "'"); + v.push_back(std::to_string(e.clickunk7)); + v.push_back(std::to_string(e.procunk1)); + v.push_back(std::to_string(e.procunk2)); + v.push_back(std::to_string(e.procunk3)); + v.push_back(std::to_string(e.procunk4)); + v.push_back("'" + Strings::Escape(e.procunk6) + "'"); + v.push_back(std::to_string(e.procunk7)); + v.push_back(std::to_string(e.wornunk1)); + v.push_back(std::to_string(e.wornunk2)); + v.push_back(std::to_string(e.wornunk3)); + v.push_back(std::to_string(e.wornunk4)); + v.push_back(std::to_string(e.wornunk5)); + v.push_back("'" + Strings::Escape(e.wornunk6) + "'"); + v.push_back(std::to_string(e.wornunk7)); + v.push_back(std::to_string(e.focusunk1)); + v.push_back(std::to_string(e.focusunk2)); + v.push_back(std::to_string(e.focusunk3)); + v.push_back(std::to_string(e.focusunk4)); + v.push_back(std::to_string(e.focusunk5)); + v.push_back("'" + Strings::Escape(e.focusunk6) + "'"); + v.push_back(std::to_string(e.focusunk7)); + v.push_back(std::to_string(e.scrollunk1)); + v.push_back(std::to_string(e.scrollunk2)); + v.push_back(std::to_string(e.scrollunk3)); + v.push_back(std::to_string(e.scrollunk4)); + v.push_back(std::to_string(e.scrollunk5)); + v.push_back("'" + Strings::Escape(e.scrollunk6) + "'"); + v.push_back(std::to_string(e.scrollunk7)); + v.push_back(std::to_string(e.UNK193)); + v.push_back(std::to_string(e.purity)); + v.push_back(std::to_string(e.evoitem)); + v.push_back(std::to_string(e.evoid)); + v.push_back(std::to_string(e.evolvinglevel)); + v.push_back(std::to_string(e.evomax)); + v.push_back("'" + Strings::Escape(e.clickname) + "'"); + v.push_back("'" + Strings::Escape(e.procname) + "'"); + v.push_back("'" + Strings::Escape(e.wornname) + "'"); + v.push_back("'" + Strings::Escape(e.focusname) + "'"); + v.push_back("'" + Strings::Escape(e.scrollname) + "'"); + v.push_back(std::to_string(e.dsmitigation)); + v.push_back(std::to_string(e.heroic_str)); + v.push_back(std::to_string(e.heroic_int)); + v.push_back(std::to_string(e.heroic_wis)); + v.push_back(std::to_string(e.heroic_agi)); + v.push_back(std::to_string(e.heroic_dex)); + v.push_back(std::to_string(e.heroic_sta)); + v.push_back(std::to_string(e.heroic_cha)); + v.push_back(std::to_string(e.heroic_pr)); + v.push_back(std::to_string(e.heroic_dr)); + v.push_back(std::to_string(e.heroic_fr)); + v.push_back(std::to_string(e.heroic_cr)); + v.push_back(std::to_string(e.heroic_mr)); + v.push_back(std::to_string(e.heroic_svcorrup)); + v.push_back(std::to_string(e.healamt)); + v.push_back(std::to_string(e.spelldmg)); + v.push_back(std::to_string(e.clairvoyance)); + v.push_back(std::to_string(e.backstabdmg)); + v.push_back("'" + Strings::Escape(e.created) + "'"); + v.push_back(std::to_string(e.elitematerial)); + v.push_back(std::to_string(e.ldonsellbackrate)); + v.push_back(std::to_string(e.scriptfileid)); + v.push_back(std::to_string(e.expendablearrow)); + v.push_back(std::to_string(e.powersourcecapacity)); + v.push_back(std::to_string(e.bardeffect)); + v.push_back(std::to_string(e.bardeffecttype)); + v.push_back(std::to_string(e.bardlevel2)); + v.push_back(std::to_string(e.bardlevel)); + v.push_back(std::to_string(e.bardunk1)); + v.push_back(std::to_string(e.bardunk2)); + v.push_back(std::to_string(e.bardunk3)); + v.push_back(std::to_string(e.bardunk4)); + v.push_back(std::to_string(e.bardunk5)); + v.push_back("'" + Strings::Escape(e.bardname) + "'"); + v.push_back(std::to_string(e.bardunk7)); + v.push_back(std::to_string(e.UNK214)); + v.push_back(std::to_string(e.subtype)); + v.push_back(std::to_string(e.UNK220)); + v.push_back(std::to_string(e.UNK221)); + v.push_back(std::to_string(e.heirloom)); + v.push_back(std::to_string(e.UNK223)); + v.push_back(std::to_string(e.UNK224)); + v.push_back(std::to_string(e.UNK225)); + v.push_back(std::to_string(e.UNK226)); + v.push_back(std::to_string(e.UNK227)); + v.push_back(std::to_string(e.UNK228)); + v.push_back(std::to_string(e.UNK229)); + v.push_back(std::to_string(e.UNK230)); + v.push_back(std::to_string(e.UNK231)); + v.push_back(std::to_string(e.UNK232)); + v.push_back(std::to_string(e.UNK233)); + v.push_back(std::to_string(e.UNK234)); + v.push_back(std::to_string(e.placeable)); + v.push_back(std::to_string(e.UNK236)); + v.push_back(std::to_string(e.UNK237)); + v.push_back(std::to_string(e.UNK238)); + v.push_back(std::to_string(e.UNK239)); + v.push_back(std::to_string(e.UNK240)); + v.push_back(std::to_string(e.UNK241)); + v.push_back(std::to_string(e.epicitem)); + + 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_ITEMS_REPOSITORY_H diff --git a/common/repositories/base/base_ldon_trap_entries_repository.h b/common/repositories/base/base_ldon_trap_entries_repository.h index d47f815be..193d8fdb4 100644 --- a/common/repositories/base/base_ldon_trap_entries_repository.h +++ b/common/repositories/base/base_ldon_trap_entries_repository.h @@ -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_LDON_TRAP_ENTRIES_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), ldon_trap_entries_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { LdonTrapEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.trap_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.trap_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LdonTrapEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.trap_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.trap_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LdonTrapEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.trap_id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.trap_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 LdonTrapEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.trap_id)); + + 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(std::to_string(e.trap_id)); + + 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_LDON_TRAP_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_ldon_trap_templates_repository.h b/common/repositories/base/base_ldon_trap_templates_repository.h index 5a4281db6..29584e7e0 100644 --- a/common/repositories/base/base_ldon_trap_templates_repository.h +++ b/common/repositories/base/base_ldon_trap_templates_repository.h @@ -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_LDON_TRAP_TEMPLATES_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), ldon_trap_templates_id ) ); @@ -130,11 +131,11 @@ public: if (results.RowCount() == 1) { LdonTrapTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.skill = static_cast(strtoul(row[3], nullptr, 10)); - e.locked = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.skill = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.locked = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; return e; } @@ -266,11 +267,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LdonTrapTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.skill = static_cast(strtoul(row[3], nullptr, 10)); - e.locked = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.skill = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.locked = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -295,11 +296,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LdonTrapTemplates e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.spell_id = static_cast(strtoul(row[2], nullptr, 10)); - e.skill = static_cast(strtoul(row[3], nullptr, 10)); - e.locked = static_cast(strtoul(row[4], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; + e.spell_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.skill = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.locked = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -358,6 +359,70 @@ 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 LdonTrapTemplates &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.locked)); + + 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(std::to_string(e.type)); + v.push_back(std::to_string(e.spell_id)); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.locked)); + + 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_LDON_TRAP_TEMPLATES_REPOSITORY_H diff --git a/common/repositories/base/base_level_exp_mods_repository.h b/common/repositories/base/base_level_exp_mods_repository.h index 13dcb2cfd..61aa8448c 100644 --- a/common/repositories/base/base_level_exp_mods_repository.h +++ b/common/repositories/base/base_level_exp_mods_repository.h @@ -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_LEVEL_EXP_MODS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), level_exp_mods_id ) ); @@ -123,8 +124,8 @@ public: LevelExpMods e{}; e.level = static_cast(atoi(row[0])); - e.exp_mod = strtof(row[1], nullptr); - e.aa_exp_mod = strtof(row[2], nullptr); + e.exp_mod = row[1] ? strtof(row[1], nullptr) : 0; + e.aa_exp_mod = row[2] ? strtof(row[2], nullptr) : 0; return e; } @@ -251,8 +252,8 @@ public: LevelExpMods e{}; e.level = static_cast(atoi(row[0])); - e.exp_mod = strtof(row[1], nullptr); - e.aa_exp_mod = strtof(row[2], nullptr); + e.exp_mod = row[1] ? strtof(row[1], nullptr) : 0; + e.aa_exp_mod = row[2] ? strtof(row[2], nullptr) : 0; all_entries.push_back(e); } @@ -278,8 +279,8 @@ public: LevelExpMods e{}; e.level = static_cast(atoi(row[0])); - e.exp_mod = strtof(row[1], nullptr); - e.aa_exp_mod = strtof(row[2], nullptr); + e.exp_mod = row[1] ? strtof(row[1], nullptr) : 0; + e.aa_exp_mod = row[2] ? strtof(row[2], nullptr) : 0; all_entries.push_back(e); } @@ -338,6 +339,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 LevelExpMods &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.exp_mod)); + v.push_back(std::to_string(e.aa_exp_mod)); + + 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.level)); + v.push_back(std::to_string(e.exp_mod)); + v.push_back(std::to_string(e.aa_exp_mod)); + + 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_LEVEL_EXP_MODS_REPOSITORY_H diff --git a/common/repositories/base/base_lfguild_repository.h b/common/repositories/base/base_lfguild_repository.h index 3fef33af2..5f91668d3 100644 --- a/common/repositories/base/base_lfguild_repository.h +++ b/common/repositories/base/base_lfguild_repository.h @@ -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_LFGUILD_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), lfguild_id ) ); @@ -146,15 +147,15 @@ public: if (results.RowCount() == 1) { Lfguild e{}; - e.type = static_cast(strtoul(row[0], nullptr, 10)); + e.type = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.comment = row[2] ? row[2] : ""; - e.fromlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.tolevel = static_cast(strtoul(row[4], nullptr, 10)); - e.classes = static_cast(strtoul(row[5], nullptr, 10)); - e.aacount = static_cast(strtoul(row[6], nullptr, 10)); - e.timezone = static_cast(strtoul(row[7], nullptr, 10)); - e.timeposted = static_cast(strtoul(row[8], nullptr, 10)); + e.fromlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.tolevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.classes = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aacount = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.timezone = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.timeposted = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; return e; } @@ -298,15 +299,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Lfguild e{}; - e.type = static_cast(strtoul(row[0], nullptr, 10)); + e.type = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.comment = row[2] ? row[2] : ""; - e.fromlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.tolevel = static_cast(strtoul(row[4], nullptr, 10)); - e.classes = static_cast(strtoul(row[5], nullptr, 10)); - e.aacount = static_cast(strtoul(row[6], nullptr, 10)); - e.timezone = static_cast(strtoul(row[7], nullptr, 10)); - e.timeposted = static_cast(strtoul(row[8], nullptr, 10)); + e.fromlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.tolevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.classes = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aacount = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.timezone = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.timeposted = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -331,15 +332,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Lfguild e{}; - e.type = static_cast(strtoul(row[0], nullptr, 10)); + e.type = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.comment = row[2] ? row[2] : ""; - e.fromlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.tolevel = static_cast(strtoul(row[4], nullptr, 10)); - e.classes = static_cast(strtoul(row[5], nullptr, 10)); - e.aacount = static_cast(strtoul(row[6], nullptr, 10)); - e.timezone = static_cast(strtoul(row[7], nullptr, 10)); - e.timeposted = static_cast(strtoul(row[8], nullptr, 10)); + e.fromlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.tolevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.classes = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.aacount = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.timezone = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.timeposted = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -398,6 +399,78 @@ 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 Lfguild &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.fromlevel)); + v.push_back(std::to_string(e.tolevel)); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.aacount)); + v.push_back(std::to_string(e.timezone)); + v.push_back(std::to_string(e.timeposted)); + + 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.type)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.comment) + "'"); + v.push_back(std::to_string(e.fromlevel)); + v.push_back(std::to_string(e.tolevel)); + v.push_back(std::to_string(e.classes)); + v.push_back(std::to_string(e.aacount)); + v.push_back(std::to_string(e.timezone)); + v.push_back(std::to_string(e.timeposted)); + + 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_LFGUILD_REPOSITORY_H diff --git a/common/repositories/base/base_login_accounts_repository.h b/common/repositories/base/base_login_accounts_repository.h index 4ac86f8d1..ed7610e4e 100644 --- a/common/repositories/base/base_login_accounts_repository.h +++ b/common/repositories/base/base_login_accounts_repository.h @@ -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_LOGIN_ACCOUNTS_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), login_accounts_id ) ); @@ -146,7 +147,7 @@ public: if (results.RowCount() == 1) { LoginAccounts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.account_email = row[3] ? row[3] : ""; @@ -298,7 +299,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginAccounts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.account_email = row[3] ? row[3] : ""; @@ -331,7 +332,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginAccounts e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.account_email = row[3] ? row[3] : ""; @@ -398,6 +399,78 @@ 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 LoginAccounts &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.account_name) + "'"); + v.push_back("'" + Strings::Escape(e.account_password) + "'"); + v.push_back("'" + Strings::Escape(e.account_email) + "'"); + v.push_back("'" + Strings::Escape(e.source_loginserver) + "'"); + v.push_back("'" + Strings::Escape(e.last_ip_address) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.last_login_date > 0 ? std::to_string(e.last_login_date) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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.account_name) + "'"); + v.push_back("'" + Strings::Escape(e.account_password) + "'"); + v.push_back("'" + Strings::Escape(e.account_email) + "'"); + v.push_back("'" + Strings::Escape(e.source_loginserver) + "'"); + v.push_back("'" + Strings::Escape(e.last_ip_address) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.last_login_date > 0 ? std::to_string(e.last_login_date) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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_LOGIN_ACCOUNTS_REPOSITORY_H diff --git a/common/repositories/base/base_login_api_tokens_repository.h b/common/repositories/base/base_login_api_tokens_repository.h index 3f5a107d3..e126f80cd 100644 --- a/common/repositories/base/base_login_api_tokens_repository.h +++ b/common/repositories/base/base_login_api_tokens_repository.h @@ -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_LOGIN_API_TOKENS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), login_api_tokens_id ) ); @@ -367,6 +368,72 @@ 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 LoginApiTokens &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.token) + "'"); + v.push_back(std::to_string(e.can_write)); + v.push_back(std::to_string(e.can_read)); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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.token) + "'"); + v.push_back(std::to_string(e.can_write)); + v.push_back(std::to_string(e.can_read)); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.updated_at > 0 ? std::to_string(e.updated_at) : "null") + ")"); + + 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_LOGIN_API_TOKENS_REPOSITORY_H diff --git a/common/repositories/base/base_login_server_admins_repository.h b/common/repositories/base/base_login_server_admins_repository.h index 297dbd312..2ec6237c2 100644 --- a/common/repositories/base/base_login_server_admins_repository.h +++ b/common/repositories/base/base_login_server_admins_repository.h @@ -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_LOGIN_SERVER_ADMINS_REPOSITORY_H @@ -132,8 +132,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), login_server_admins_id ) ); @@ -142,7 +143,7 @@ public: if (results.RowCount() == 1) { LoginServerAdmins e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.first_name = row[3] ? row[3] : ""; @@ -289,7 +290,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginServerAdmins e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.first_name = row[3] ? row[3] : ""; @@ -321,7 +322,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginServerAdmins e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.account_name = row[1] ? row[1] : ""; e.account_password = row[2] ? row[2] : ""; e.first_name = row[3] ? row[3] : ""; @@ -387,6 +388,76 @@ 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 LoginServerAdmins &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.account_name) + "'"); + v.push_back("'" + Strings::Escape(e.account_password) + "'"); + v.push_back("'" + Strings::Escape(e.first_name) + "'"); + v.push_back("'" + Strings::Escape(e.last_name) + "'"); + v.push_back("'" + Strings::Escape(e.email) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.registration_date > 0 ? std::to_string(e.registration_date) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.registration_ip_address) + "'"); + + 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.account_name) + "'"); + v.push_back("'" + Strings::Escape(e.account_password) + "'"); + v.push_back("'" + Strings::Escape(e.first_name) + "'"); + v.push_back("'" + Strings::Escape(e.last_name) + "'"); + v.push_back("'" + Strings::Escape(e.email) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.registration_date > 0 ? std::to_string(e.registration_date) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.registration_ip_address) + "'"); + + 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_LOGIN_SERVER_ADMINS_REPOSITORY_H diff --git a/common/repositories/base/base_login_server_list_types_repository.h b/common/repositories/base/base_login_server_list_types_repository.h index 9973d28aa..0a1314a4d 100644 --- a/common/repositories/base/base_login_server_list_types_repository.h +++ b/common/repositories/base/base_login_server_list_types_repository.h @@ -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_LOGIN_SERVER_LIST_TYPES_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), login_server_list_types_id ) ); @@ -118,7 +119,7 @@ public: if (results.RowCount() == 1) { LoginServerListTypes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.description = row[1] ? row[1] : ""; return e; @@ -242,7 +243,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginServerListTypes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.description = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -268,7 +269,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginServerListTypes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.description = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -328,6 +329,64 @@ 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 LoginServerListTypes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.description) + "'"); + + 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.description) + "'"); + + 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_LOGIN_SERVER_LIST_TYPES_REPOSITORY_H diff --git a/common/repositories/base/base_login_world_servers_repository.h b/common/repositories/base/base_login_world_servers_repository.h index 850f233a8..864638273 100644 --- a/common/repositories/base/base_login_world_servers_repository.h +++ b/common/repositories/base/base_login_world_servers_repository.h @@ -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_LOGIN_WORLD_SERVERS_REPOSITORY_H @@ -140,8 +140,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), login_world_servers_id ) ); @@ -150,7 +151,7 @@ public: if (results.RowCount() == 1) { LoginWorldServers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.long_name = row[1] ? row[1] : ""; e.short_name = row[2] ? row[2] : ""; e.tag_description = row[3] ? row[3] : ""; @@ -305,7 +306,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginWorldServers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.long_name = row[1] ? row[1] : ""; e.short_name = row[2] ? row[2] : ""; e.tag_description = row[3] ? row[3] : ""; @@ -339,7 +340,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoginWorldServers e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.long_name = row[1] ? row[1] : ""; e.short_name = row[2] ? row[2] : ""; e.tag_description = row[3] ? row[3] : ""; @@ -407,6 +408,80 @@ 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 LoginWorldServers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.long_name) + "'"); + v.push_back("'" + Strings::Escape(e.short_name) + "'"); + v.push_back("'" + Strings::Escape(e.tag_description) + "'"); + v.push_back(std::to_string(e.login_server_list_type_id)); + v.push_back("FROM_UNIXTIME(" + (e.last_login_date > 0 ? std::to_string(e.last_login_date) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.last_ip_address) + "'"); + v.push_back(std::to_string(e.login_server_admin_id)); + v.push_back(std::to_string(e.is_server_trusted)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + + 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.long_name) + "'"); + v.push_back("'" + Strings::Escape(e.short_name) + "'"); + v.push_back("'" + Strings::Escape(e.tag_description) + "'"); + v.push_back(std::to_string(e.login_server_list_type_id)); + v.push_back("FROM_UNIXTIME(" + (e.last_login_date > 0 ? std::to_string(e.last_login_date) : "null") + ")"); + v.push_back("'" + Strings::Escape(e.last_ip_address) + "'"); + v.push_back(std::to_string(e.login_server_admin_id)); + v.push_back(std::to_string(e.is_server_trusted)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + + 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_LOGIN_WORLD_SERVERS_REPOSITORY_H diff --git a/common/repositories/base/base_logsys_categories_repository.h b/common/repositories/base/base_logsys_categories_repository.h index 5c0abcc14..804a5f4ad 100644 --- a/common/repositories/base/base_logsys_categories_repository.h +++ b/common/repositories/base/base_logsys_categories_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseLogsysCategoriesRepository { public: struct LogsysCategories { diff --git a/common/repositories/base/base_lootdrop_entries_repository.h b/common/repositories/base/base_lootdrop_entries_repository.h index 48a0cf337..de5e312b5 100644 --- a/common/repositories/base/base_lootdrop_entries_repository.h +++ b/common/repositories/base/base_lootdrop_entries_repository.h @@ -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_LOOTDROP_ENTRIES_REPOSITORY_H @@ -144,8 +144,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), lootdrop_entries_id ) ); @@ -154,17 +155,17 @@ public: if (results.RowCount() == 1) { LootdropEntries e{}; - e.lootdrop_id = static_cast(strtoul(row[0], nullptr, 10)); + e.lootdrop_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.item_id = static_cast(atoi(row[1])); - e.item_charges = static_cast(strtoul(row[2], nullptr, 10)); - e.equip_item = static_cast(strtoul(row[3], nullptr, 10)); - e.chance = strtof(row[4], nullptr); - e.disabled_chance = strtof(row[5], nullptr); - e.trivial_min_level = static_cast(strtoul(row[6], nullptr, 10)); - e.trivial_max_level = static_cast(strtoul(row[7], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[8], nullptr, 10)); - e.npc_min_level = static_cast(strtoul(row[9], nullptr, 10)); - e.npc_max_level = static_cast(strtoul(row[10], nullptr, 10)); + e.item_charges = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.equip_item = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.chance = row[4] ? strtof(row[4], nullptr) : 1; + e.disabled_chance = row[5] ? strtof(row[5], nullptr) : 0; + e.trivial_min_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.trivial_max_level = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.multiplier = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 1; + e.npc_min_level = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.npc_max_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; return e; } @@ -314,17 +315,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LootdropEntries e{}; - e.lootdrop_id = static_cast(strtoul(row[0], nullptr, 10)); + e.lootdrop_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.item_id = static_cast(atoi(row[1])); - e.item_charges = static_cast(strtoul(row[2], nullptr, 10)); - e.equip_item = static_cast(strtoul(row[3], nullptr, 10)); - e.chance = strtof(row[4], nullptr); - e.disabled_chance = strtof(row[5], nullptr); - e.trivial_min_level = static_cast(strtoul(row[6], nullptr, 10)); - e.trivial_max_level = static_cast(strtoul(row[7], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[8], nullptr, 10)); - e.npc_min_level = static_cast(strtoul(row[9], nullptr, 10)); - e.npc_max_level = static_cast(strtoul(row[10], nullptr, 10)); + e.item_charges = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.equip_item = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.chance = row[4] ? strtof(row[4], nullptr) : 1; + e.disabled_chance = row[5] ? strtof(row[5], nullptr) : 0; + e.trivial_min_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.trivial_max_level = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.multiplier = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 1; + e.npc_min_level = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.npc_max_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -349,17 +350,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LootdropEntries e{}; - e.lootdrop_id = static_cast(strtoul(row[0], nullptr, 10)); + e.lootdrop_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.item_id = static_cast(atoi(row[1])); - e.item_charges = static_cast(strtoul(row[2], nullptr, 10)); - e.equip_item = static_cast(strtoul(row[3], nullptr, 10)); - e.chance = strtof(row[4], nullptr); - e.disabled_chance = strtof(row[5], nullptr); - e.trivial_min_level = static_cast(strtoul(row[6], nullptr, 10)); - e.trivial_max_level = static_cast(strtoul(row[7], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[8], nullptr, 10)); - e.npc_min_level = static_cast(strtoul(row[9], nullptr, 10)); - e.npc_max_level = static_cast(strtoul(row[10], nullptr, 10)); + e.item_charges = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.equip_item = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.chance = row[4] ? strtof(row[4], nullptr) : 1; + e.disabled_chance = row[5] ? strtof(row[5], nullptr) : 0; + e.trivial_min_level = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.trivial_max_level = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.multiplier = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 1; + e.npc_min_level = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.npc_max_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -418,6 +419,82 @@ 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 LootdropEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.lootdrop_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.item_charges)); + v.push_back(std::to_string(e.equip_item)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.disabled_chance)); + v.push_back(std::to_string(e.trivial_min_level)); + v.push_back(std::to_string(e.trivial_max_level)); + v.push_back(std::to_string(e.multiplier)); + v.push_back(std::to_string(e.npc_min_level)); + v.push_back(std::to_string(e.npc_max_level)); + + 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.lootdrop_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.item_charges)); + v.push_back(std::to_string(e.equip_item)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.disabled_chance)); + v.push_back(std::to_string(e.trivial_min_level)); + v.push_back(std::to_string(e.trivial_max_level)); + v.push_back(std::to_string(e.multiplier)); + v.push_back(std::to_string(e.npc_min_level)); + v.push_back(std::to_string(e.npc_max_level)); + + 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_LOOTDROP_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_lootdrop_repository.h b/common/repositories/base/base_lootdrop_repository.h index 6361dd6bf..504d8fdfb 100644 --- a/common/repositories/base/base_lootdrop_repository.h +++ b/common/repositories/base/base_lootdrop_repository.h @@ -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_LOOTDROP_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), lootdrop_id ) ); @@ -134,7 +135,7 @@ public: if (results.RowCount() == 1) { Lootdrop e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.min_expansion = static_cast(atoi(row[2])); e.max_expansion = static_cast(atoi(row[3])); @@ -273,7 +274,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Lootdrop e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.min_expansion = static_cast(atoi(row[2])); e.max_expansion = static_cast(atoi(row[3])); @@ -303,7 +304,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Lootdrop e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.min_expansion = static_cast(atoi(row[2])); e.max_expansion = static_cast(atoi(row[3])); @@ -367,6 +368,72 @@ 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 Lootdrop &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + 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) + "'"); + + 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.name) + "'"); + 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) + "'"); + + 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_LOOTDROP_REPOSITORY_H diff --git a/common/repositories/base/base_loottable_entries_repository.h b/common/repositories/base/base_loottable_entries_repository.h index f36d8026a..3bea64839 100644 --- a/common/repositories/base/base_loottable_entries_repository.h +++ b/common/repositories/base/base_loottable_entries_repository.h @@ -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_LOOTTABLE_ENTRIES_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), loottable_entries_id ) ); @@ -134,12 +135,12 @@ public: if (results.RowCount() == 1) { LoottableEntries e{}; - e.loottable_id = static_cast(strtoul(row[0], nullptr, 10)); - e.lootdrop_id = static_cast(strtoul(row[1], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[2], nullptr, 10)); - e.droplimit = static_cast(strtoul(row[3], nullptr, 10)); - e.mindrop = static_cast(strtoul(row[4], nullptr, 10)); - e.probability = strtof(row[5], nullptr); + e.loottable_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lootdrop_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.multiplier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.droplimit = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.mindrop = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.probability = row[5] ? strtof(row[5], nullptr) : 100; return e; } @@ -274,12 +275,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoottableEntries e{}; - e.loottable_id = static_cast(strtoul(row[0], nullptr, 10)); - e.lootdrop_id = static_cast(strtoul(row[1], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[2], nullptr, 10)); - e.droplimit = static_cast(strtoul(row[3], nullptr, 10)); - e.mindrop = static_cast(strtoul(row[4], nullptr, 10)); - e.probability = strtof(row[5], nullptr); + e.loottable_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lootdrop_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.multiplier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.droplimit = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.mindrop = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.probability = row[5] ? strtof(row[5], nullptr) : 100; all_entries.push_back(e); } @@ -304,12 +305,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { LoottableEntries e{}; - e.loottable_id = static_cast(strtoul(row[0], nullptr, 10)); - e.lootdrop_id = static_cast(strtoul(row[1], nullptr, 10)); - e.multiplier = static_cast(strtoul(row[2], nullptr, 10)); - e.droplimit = static_cast(strtoul(row[3], nullptr, 10)); - e.mindrop = static_cast(strtoul(row[4], nullptr, 10)); - e.probability = strtof(row[5], nullptr); + e.loottable_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.lootdrop_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.multiplier = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 1; + e.droplimit = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.mindrop = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.probability = row[5] ? strtof(row[5], nullptr) : 100; all_entries.push_back(e); } @@ -368,6 +369,72 @@ 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 LoottableEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.loottable_id)); + v.push_back(std::to_string(e.lootdrop_id)); + v.push_back(std::to_string(e.multiplier)); + v.push_back(std::to_string(e.droplimit)); + v.push_back(std::to_string(e.mindrop)); + v.push_back(std::to_string(e.probability)); + + 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.loottable_id)); + v.push_back(std::to_string(e.lootdrop_id)); + v.push_back(std::to_string(e.multiplier)); + v.push_back(std::to_string(e.droplimit)); + v.push_back(std::to_string(e.mindrop)); + v.push_back(std::to_string(e.probability)); + + 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_LOOTTABLE_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_loottable_repository.h b/common/repositories/base/base_loottable_repository.h index 44d5156f0..eedd05788 100644 --- a/common/repositories/base/base_loottable_repository.h +++ b/common/repositories/base/base_loottable_repository.h @@ -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_LOOTTABLE_REPOSITORY_H @@ -140,8 +140,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), loottable_id ) ); @@ -150,11 +151,11 @@ public: if (results.RowCount() == 1) { Loottable e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.mincash = static_cast(strtoul(row[2], nullptr, 10)); - e.maxcash = static_cast(strtoul(row[3], nullptr, 10)); - e.avgcoin = static_cast(strtoul(row[4], nullptr, 10)); + e.mincash = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.maxcash = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.avgcoin = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.done = static_cast(atoi(row[5])); e.min_expansion = static_cast(atoi(row[6])); e.max_expansion = static_cast(atoi(row[7])); @@ -305,11 +306,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Loottable e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.mincash = static_cast(strtoul(row[2], nullptr, 10)); - e.maxcash = static_cast(strtoul(row[3], nullptr, 10)); - e.avgcoin = static_cast(strtoul(row[4], nullptr, 10)); + e.mincash = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.maxcash = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.avgcoin = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.done = static_cast(atoi(row[5])); e.min_expansion = static_cast(atoi(row[6])); e.max_expansion = static_cast(atoi(row[7])); @@ -339,11 +340,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Loottable e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.mincash = static_cast(strtoul(row[2], nullptr, 10)); - e.maxcash = static_cast(strtoul(row[3], nullptr, 10)); - e.avgcoin = static_cast(strtoul(row[4], nullptr, 10)); + e.mincash = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.maxcash = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.avgcoin = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.done = static_cast(atoi(row[5])); e.min_expansion = static_cast(atoi(row[6])); e.max_expansion = static_cast(atoi(row[7])); @@ -407,6 +408,80 @@ 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 Loottable &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.mincash)); + v.push_back(std::to_string(e.maxcash)); + v.push_back(std::to_string(e.avgcoin)); + v.push_back(std::to_string(e.done)); + 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) + "'"); + + 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.name) + "'"); + v.push_back(std::to_string(e.mincash)); + v.push_back(std::to_string(e.maxcash)); + v.push_back(std::to_string(e.avgcoin)); + v.push_back(std::to_string(e.done)); + 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) + "'"); + + 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_LOOTTABLE_REPOSITORY_H diff --git a/common/repositories/base/base_mail_repository.h b/common/repositories/base/base_mail_repository.h index 11fcbce8d..57c3311a5 100644 --- a/common/repositories/base/base_mail_repository.h +++ b/common/repositories/base/base_mail_repository.h @@ -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_MAIL_REPOSITORY_H @@ -132,8 +132,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), mail_id ) ); @@ -142,8 +143,8 @@ public: if (results.RowCount() == 1) { Mail e{}; - e.msgid = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.msgid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.timestamp = static_cast(atoi(row[2])); e.from = row[3] ? row[3] : ""; e.subject = row[4] ? row[4] : ""; @@ -289,8 +290,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Mail e{}; - e.msgid = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.msgid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.timestamp = static_cast(atoi(row[2])); e.from = row[3] ? row[3] : ""; e.subject = row[4] ? row[4] : ""; @@ -321,8 +322,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Mail e{}; - e.msgid = static_cast(strtoul(row[0], nullptr, 10)); - e.charid = static_cast(strtoul(row[1], nullptr, 10)); + e.msgid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.charid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.timestamp = static_cast(atoi(row[2])); e.from = row[3] ? row[3] : ""; e.subject = row[4] ? row[4] : ""; @@ -387,6 +388,76 @@ 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 Mail &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.msgid)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.timestamp)); + v.push_back("'" + Strings::Escape(e.from) + "'"); + v.push_back("'" + Strings::Escape(e.subject) + "'"); + v.push_back("'" + Strings::Escape(e.body) + "'"); + v.push_back("'" + Strings::Escape(e.to) + "'"); + v.push_back(std::to_string(e.status)); + + 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.msgid)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.timestamp)); + v.push_back("'" + Strings::Escape(e.from) + "'"); + v.push_back("'" + Strings::Escape(e.subject) + "'"); + v.push_back("'" + Strings::Escape(e.body) + "'"); + v.push_back("'" + Strings::Escape(e.to) + "'"); + v.push_back(std::to_string(e.status)); + + 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_MAIL_REPOSITORY_H diff --git a/common/repositories/base/base_merc_buffs_repository.h b/common/repositories/base/base_merc_buffs_repository.h index c210178cf..d067b1455 100644 --- a/common/repositories/base/base_merc_buffs_repository.h +++ b/common/repositories/base/base_merc_buffs_repository.h @@ -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_MERC_BUFFS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseMercBuffsRepository { public: struct MercBuffs { @@ -188,19 +187,19 @@ public: if (results.RowCount() == 1) { MercBuffs e{}; - e.MercBuffId = static_cast(strtoul(row[0], nullptr, 10)); - e.MercId = static_cast(strtoul(row[1], nullptr, 10)); - e.SpellId = static_cast(strtoul(row[2], nullptr, 10)); - e.CasterLevel = static_cast(strtoul(row[3], nullptr, 10)); - e.DurationFormula = static_cast(strtoul(row[4], nullptr, 10)); + e.MercBuffId = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.MercId = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.SpellId = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.CasterLevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.DurationFormula = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.TicsRemaining = static_cast(atoi(row[5])); - e.PoisonCounters = static_cast(strtoul(row[6], nullptr, 10)); - e.DiseaseCounters = static_cast(strtoul(row[7], nullptr, 10)); - e.CurseCounters = static_cast(strtoul(row[8], nullptr, 10)); - e.CorruptionCounters = static_cast(strtoul(row[9], nullptr, 10)); - e.HitCount = static_cast(strtoul(row[10], nullptr, 10)); - e.MeleeRune = static_cast(strtoul(row[11], nullptr, 10)); - e.MagicRune = static_cast(strtoul(row[12], nullptr, 10)); + e.PoisonCounters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.DiseaseCounters = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.CurseCounters = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.CorruptionCounters = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.HitCount = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.MeleeRune = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.MagicRune = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[13])); e.caston_x = static_cast(atoi(row[14])); e.Persistent = static_cast(atoi(row[15])); @@ -379,19 +378,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { MercBuffs e{}; - e.MercBuffId = static_cast(strtoul(row[0], nullptr, 10)); - e.MercId = static_cast(strtoul(row[1], nullptr, 10)); - e.SpellId = static_cast(strtoul(row[2], nullptr, 10)); - e.CasterLevel = static_cast(strtoul(row[3], nullptr, 10)); - e.DurationFormula = static_cast(strtoul(row[4], nullptr, 10)); + e.MercBuffId = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.MercId = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.SpellId = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.CasterLevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.DurationFormula = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.TicsRemaining = static_cast(atoi(row[5])); - e.PoisonCounters = static_cast(strtoul(row[6], nullptr, 10)); - e.DiseaseCounters = static_cast(strtoul(row[7], nullptr, 10)); - e.CurseCounters = static_cast(strtoul(row[8], nullptr, 10)); - e.CorruptionCounters = static_cast(strtoul(row[9], nullptr, 10)); - e.HitCount = static_cast(strtoul(row[10], nullptr, 10)); - e.MeleeRune = static_cast(strtoul(row[11], nullptr, 10)); - e.MagicRune = static_cast(strtoul(row[12], nullptr, 10)); + e.PoisonCounters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.DiseaseCounters = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.CurseCounters = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.CorruptionCounters = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.HitCount = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.MeleeRune = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.MagicRune = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[13])); e.caston_x = static_cast(atoi(row[14])); e.Persistent = static_cast(atoi(row[15])); @@ -422,19 +421,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { MercBuffs e{}; - e.MercBuffId = static_cast(strtoul(row[0], nullptr, 10)); - e.MercId = static_cast(strtoul(row[1], nullptr, 10)); - e.SpellId = static_cast(strtoul(row[2], nullptr, 10)); - e.CasterLevel = static_cast(strtoul(row[3], nullptr, 10)); - e.DurationFormula = static_cast(strtoul(row[4], nullptr, 10)); + e.MercBuffId = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.MercId = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.SpellId = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.CasterLevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.DurationFormula = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.TicsRemaining = static_cast(atoi(row[5])); - e.PoisonCounters = static_cast(strtoul(row[6], nullptr, 10)); - e.DiseaseCounters = static_cast(strtoul(row[7], nullptr, 10)); - e.CurseCounters = static_cast(strtoul(row[8], nullptr, 10)); - e.CorruptionCounters = static_cast(strtoul(row[9], nullptr, 10)); - e.HitCount = static_cast(strtoul(row[10], nullptr, 10)); - e.MeleeRune = static_cast(strtoul(row[11], nullptr, 10)); - e.MagicRune = static_cast(strtoul(row[12], nullptr, 10)); + e.PoisonCounters = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.DiseaseCounters = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.CurseCounters = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.CorruptionCounters = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.HitCount = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.MeleeRune = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.MagicRune = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.dot_rune = static_cast(atoi(row[13])); e.caston_x = static_cast(atoi(row[14])); e.Persistent = static_cast(atoi(row[15])); @@ -499,6 +498,98 @@ 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 MercBuffs &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.MercBuffId)); + v.push_back(std::to_string(e.MercId)); + v.push_back(std::to_string(e.SpellId)); + v.push_back(std::to_string(e.CasterLevel)); + v.push_back(std::to_string(e.DurationFormula)); + v.push_back(std::to_string(e.TicsRemaining)); + v.push_back(std::to_string(e.PoisonCounters)); + v.push_back(std::to_string(e.DiseaseCounters)); + v.push_back(std::to_string(e.CurseCounters)); + v.push_back(std::to_string(e.CorruptionCounters)); + v.push_back(std::to_string(e.HitCount)); + v.push_back(std::to_string(e.MeleeRune)); + v.push_back(std::to_string(e.MagicRune)); + v.push_back(std::to_string(e.dot_rune)); + v.push_back(std::to_string(e.caston_x)); + v.push_back(std::to_string(e.Persistent)); + v.push_back(std::to_string(e.caston_y)); + v.push_back(std::to_string(e.caston_z)); + v.push_back(std::to_string(e.ExtraDIChance)); + + 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.MercBuffId)); + v.push_back(std::to_string(e.MercId)); + v.push_back(std::to_string(e.SpellId)); + v.push_back(std::to_string(e.CasterLevel)); + v.push_back(std::to_string(e.DurationFormula)); + v.push_back(std::to_string(e.TicsRemaining)); + v.push_back(std::to_string(e.PoisonCounters)); + v.push_back(std::to_string(e.DiseaseCounters)); + v.push_back(std::to_string(e.CurseCounters)); + v.push_back(std::to_string(e.CorruptionCounters)); + v.push_back(std::to_string(e.HitCount)); + v.push_back(std::to_string(e.MeleeRune)); + v.push_back(std::to_string(e.MagicRune)); + v.push_back(std::to_string(e.dot_rune)); + v.push_back(std::to_string(e.caston_x)); + v.push_back(std::to_string(e.Persistent)); + v.push_back(std::to_string(e.caston_y)); + v.push_back(std::to_string(e.caston_z)); + v.push_back(std::to_string(e.ExtraDIChance)); + + 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_MERC_BUFFS_REPOSITORY_H diff --git a/common/repositories/base/base_merchantlist_repository.h b/common/repositories/base/base_merchantlist_repository.h index 7c9a3e8da..d341d7f35 100644 --- a/common/repositories/base/base_merchantlist_repository.h +++ b/common/repositories/base/base_merchantlist_repository.h @@ -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_MERCHANTLIST_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseMerchantlistRepository { public: struct Merchantlist { @@ -184,15 +183,15 @@ public: e.slot = static_cast(atoi(row[1])); e.item = static_cast(atoi(row[2])); e.faction_required = static_cast(atoi(row[3])); - e.level_required = static_cast(strtoul(row[4], nullptr, 10)); - e.min_status = static_cast(strtoul(row[5], nullptr, 10)); - e.max_status = static_cast(strtoul(row[6], nullptr, 10)); - e.alt_currency_cost = static_cast(strtoul(row[7], nullptr, 10)); + e.level_required = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.max_status = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 255; + e.alt_currency_cost = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.classes_required = static_cast(atoi(row[8])); e.probability = static_cast(atoi(row[9])); e.bucket_name = row[10] ? row[10] : ""; e.bucket_value = row[11] ? row[11] : ""; - e.bucket_comparison = static_cast(strtoul(row[12], nullptr, 10)); + e.bucket_comparison = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[13])); e.max_expansion = static_cast(atoi(row[14])); e.content_flags = row[15] ? row[15] : ""; @@ -368,15 +367,15 @@ public: e.slot = static_cast(atoi(row[1])); e.item = static_cast(atoi(row[2])); e.faction_required = static_cast(atoi(row[3])); - e.level_required = static_cast(strtoul(row[4], nullptr, 10)); - e.min_status = static_cast(strtoul(row[5], nullptr, 10)); - e.max_status = static_cast(strtoul(row[6], nullptr, 10)); - e.alt_currency_cost = static_cast(strtoul(row[7], nullptr, 10)); + e.level_required = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.max_status = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 255; + e.alt_currency_cost = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.classes_required = static_cast(atoi(row[8])); e.probability = static_cast(atoi(row[9])); e.bucket_name = row[10] ? row[10] : ""; e.bucket_value = row[11] ? row[11] : ""; - e.bucket_comparison = static_cast(strtoul(row[12], nullptr, 10)); + e.bucket_comparison = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[13])); e.max_expansion = static_cast(atoi(row[14])); e.content_flags = row[15] ? row[15] : ""; @@ -409,15 +408,15 @@ public: e.slot = static_cast(atoi(row[1])); e.item = static_cast(atoi(row[2])); e.faction_required = static_cast(atoi(row[3])); - e.level_required = static_cast(strtoul(row[4], nullptr, 10)); - e.min_status = static_cast(strtoul(row[5], nullptr, 10)); - e.max_status = static_cast(strtoul(row[6], nullptr, 10)); - e.alt_currency_cost = static_cast(strtoul(row[7], nullptr, 10)); + e.level_required = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.min_status = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.max_status = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 255; + e.alt_currency_cost = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; e.classes_required = static_cast(atoi(row[8])); e.probability = static_cast(atoi(row[9])); e.bucket_name = row[10] ? row[10] : ""; e.bucket_value = row[11] ? row[11] : ""; - e.bucket_comparison = static_cast(strtoul(row[12], nullptr, 10)); + e.bucket_comparison = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[13])); e.max_expansion = static_cast(atoi(row[14])); e.content_flags = row[15] ? row[15] : ""; @@ -480,6 +479,94 @@ 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 Merchantlist &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.merchantid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.item)); + v.push_back(std::to_string(e.faction_required)); + v.push_back(std::to_string(e.level_required)); + v.push_back(std::to_string(e.min_status)); + v.push_back(std::to_string(e.max_status)); + v.push_back(std::to_string(e.alt_currency_cost)); + v.push_back(std::to_string(e.classes_required)); + v.push_back(std::to_string(e.probability)); + v.push_back("'" + Strings::Escape(e.bucket_name) + "'"); + v.push_back("'" + Strings::Escape(e.bucket_value) + "'"); + v.push_back(std::to_string(e.bucket_comparison)); + 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) + "'"); + + 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.merchantid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.item)); + v.push_back(std::to_string(e.faction_required)); + v.push_back(std::to_string(e.level_required)); + v.push_back(std::to_string(e.min_status)); + v.push_back(std::to_string(e.max_status)); + v.push_back(std::to_string(e.alt_currency_cost)); + v.push_back(std::to_string(e.classes_required)); + v.push_back(std::to_string(e.probability)); + v.push_back("'" + Strings::Escape(e.bucket_name) + "'"); + v.push_back("'" + Strings::Escape(e.bucket_value) + "'"); + v.push_back(std::to_string(e.bucket_comparison)); + 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) + "'"); + + 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_MERCHANTLIST_REPOSITORY_H diff --git a/common/repositories/base/base_merchantlist_temp_repository.h b/common/repositories/base/base_merchantlist_temp_repository.h index 99f25da49..524c73bd8 100644 --- a/common/repositories/base/base_merchantlist_temp_repository.h +++ b/common/repositories/base/base_merchantlist_temp_repository.h @@ -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_MERCHANTLIST_TEMP_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), merchantlist_temp_id ) ); @@ -134,12 +135,12 @@ public: if (results.RowCount() == 1) { MerchantlistTemp e{}; - e.npcid = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.npcid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); - e.itemid = static_cast(strtoul(row[4], nullptr, 10)); - e.charges = static_cast(strtoul(row[5], nullptr, 10)); + e.itemid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.charges = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; return e; } @@ -274,12 +275,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { MerchantlistTemp e{}; - e.npcid = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.npcid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); - e.itemid = static_cast(strtoul(row[4], nullptr, 10)); - e.charges = static_cast(strtoul(row[5], nullptr, 10)); + e.itemid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.charges = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; all_entries.push_back(e); } @@ -304,12 +305,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { MerchantlistTemp e{}; - e.npcid = static_cast(strtoul(row[0], nullptr, 10)); - e.slot = static_cast(strtoul(row[1], nullptr, 10)); + e.npcid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.slot = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone_id = static_cast(atoi(row[2])); e.instance_id = static_cast(atoi(row[3])); - e.itemid = static_cast(strtoul(row[4], nullptr, 10)); - e.charges = static_cast(strtoul(row[5], nullptr, 10)); + e.itemid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.charges = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 1; all_entries.push_back(e); } @@ -368,6 +369,72 @@ 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 MerchantlistTemp &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.npcid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + + 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.npcid)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + + 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_MERCHANTLIST_TEMP_REPOSITORY_H diff --git a/common/repositories/base/base_mercs_repository.h b/common/repositories/base/base_mercs_repository.h index 9ddb84bde..5402126ef 100644 --- a/common/repositories/base/base_mercs_repository.h +++ b/common/repositories/base/base_mercs_repository.h @@ -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_MERCS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseMercsRepository { public: struct Mercs { @@ -208,30 +207,30 @@ public: if (results.RowCount() == 1) { Mercs e{}; - e.MercID = static_cast(strtoul(row[0], nullptr, 10)); - e.OwnerCharacterID = static_cast(strtoul(row[1], nullptr, 10)); - e.Slot = static_cast(strtoul(row[2], nullptr, 10)); + e.MercID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.OwnerCharacterID = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.Slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.Name = row[3] ? row[3] : ""; - e.TemplateID = static_cast(strtoul(row[4], nullptr, 10)); - e.SuspendedTime = static_cast(strtoul(row[5], nullptr, 10)); - e.IsSuspended = static_cast(strtoul(row[6], nullptr, 10)); - e.TimerRemaining = static_cast(strtoul(row[7], nullptr, 10)); - e.Gender = static_cast(strtoul(row[8], nullptr, 10)); - e.MercSize = strtof(row[9], nullptr); - e.StanceID = static_cast(strtoul(row[10], nullptr, 10)); - e.HP = static_cast(strtoul(row[11], nullptr, 10)); - e.Mana = static_cast(strtoul(row[12], nullptr, 10)); - e.Endurance = static_cast(strtoul(row[13], nullptr, 10)); - e.Face = static_cast(strtoul(row[14], nullptr, 10)); - e.LuclinHairStyle = static_cast(strtoul(row[15], nullptr, 10)); - e.LuclinHairColor = static_cast(strtoul(row[16], nullptr, 10)); - e.LuclinEyeColor = static_cast(strtoul(row[17], nullptr, 10)); - e.LuclinEyeColor2 = static_cast(strtoul(row[18], nullptr, 10)); - e.LuclinBeardColor = static_cast(strtoul(row[19], nullptr, 10)); - e.LuclinBeard = static_cast(strtoul(row[20], nullptr, 10)); - e.DrakkinHeritage = static_cast(strtoul(row[21], nullptr, 10)); - e.DrakkinTattoo = static_cast(strtoul(row[22], nullptr, 10)); - e.DrakkinDetails = static_cast(strtoul(row[23], nullptr, 10)); + e.TemplateID = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.SuspendedTime = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.IsSuspended = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.TimerRemaining = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.Gender = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.MercSize = row[9] ? strtof(row[9], nullptr) : 5; + e.StanceID = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.HP = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.Mana = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.Endurance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.Face = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.LuclinHairStyle = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 1; + e.LuclinHairColor = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1; + e.LuclinEyeColor = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 1; + e.LuclinEyeColor2 = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; + e.LuclinBeardColor = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.LuclinBeard = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.DrakkinHeritage = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.DrakkinTattoo = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.DrakkinDetails = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; return e; } @@ -419,30 +418,30 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Mercs e{}; - e.MercID = static_cast(strtoul(row[0], nullptr, 10)); - e.OwnerCharacterID = static_cast(strtoul(row[1], nullptr, 10)); - e.Slot = static_cast(strtoul(row[2], nullptr, 10)); + e.MercID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.OwnerCharacterID = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.Slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.Name = row[3] ? row[3] : ""; - e.TemplateID = static_cast(strtoul(row[4], nullptr, 10)); - e.SuspendedTime = static_cast(strtoul(row[5], nullptr, 10)); - e.IsSuspended = static_cast(strtoul(row[6], nullptr, 10)); - e.TimerRemaining = static_cast(strtoul(row[7], nullptr, 10)); - e.Gender = static_cast(strtoul(row[8], nullptr, 10)); - e.MercSize = strtof(row[9], nullptr); - e.StanceID = static_cast(strtoul(row[10], nullptr, 10)); - e.HP = static_cast(strtoul(row[11], nullptr, 10)); - e.Mana = static_cast(strtoul(row[12], nullptr, 10)); - e.Endurance = static_cast(strtoul(row[13], nullptr, 10)); - e.Face = static_cast(strtoul(row[14], nullptr, 10)); - e.LuclinHairStyle = static_cast(strtoul(row[15], nullptr, 10)); - e.LuclinHairColor = static_cast(strtoul(row[16], nullptr, 10)); - e.LuclinEyeColor = static_cast(strtoul(row[17], nullptr, 10)); - e.LuclinEyeColor2 = static_cast(strtoul(row[18], nullptr, 10)); - e.LuclinBeardColor = static_cast(strtoul(row[19], nullptr, 10)); - e.LuclinBeard = static_cast(strtoul(row[20], nullptr, 10)); - e.DrakkinHeritage = static_cast(strtoul(row[21], nullptr, 10)); - e.DrakkinTattoo = static_cast(strtoul(row[22], nullptr, 10)); - e.DrakkinDetails = static_cast(strtoul(row[23], nullptr, 10)); + e.TemplateID = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.SuspendedTime = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.IsSuspended = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.TimerRemaining = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.Gender = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.MercSize = row[9] ? strtof(row[9], nullptr) : 5; + e.StanceID = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.HP = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.Mana = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.Endurance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.Face = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.LuclinHairStyle = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 1; + e.LuclinHairColor = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1; + e.LuclinEyeColor = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 1; + e.LuclinEyeColor2 = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; + e.LuclinBeardColor = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.LuclinBeard = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.DrakkinHeritage = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.DrakkinTattoo = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.DrakkinDetails = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -467,30 +466,30 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Mercs e{}; - e.MercID = static_cast(strtoul(row[0], nullptr, 10)); - e.OwnerCharacterID = static_cast(strtoul(row[1], nullptr, 10)); - e.Slot = static_cast(strtoul(row[2], nullptr, 10)); + e.MercID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.OwnerCharacterID = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.Slot = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.Name = row[3] ? row[3] : ""; - e.TemplateID = static_cast(strtoul(row[4], nullptr, 10)); - e.SuspendedTime = static_cast(strtoul(row[5], nullptr, 10)); - e.IsSuspended = static_cast(strtoul(row[6], nullptr, 10)); - e.TimerRemaining = static_cast(strtoul(row[7], nullptr, 10)); - e.Gender = static_cast(strtoul(row[8], nullptr, 10)); - e.MercSize = strtof(row[9], nullptr); - e.StanceID = static_cast(strtoul(row[10], nullptr, 10)); - e.HP = static_cast(strtoul(row[11], nullptr, 10)); - e.Mana = static_cast(strtoul(row[12], nullptr, 10)); - e.Endurance = static_cast(strtoul(row[13], nullptr, 10)); - e.Face = static_cast(strtoul(row[14], nullptr, 10)); - e.LuclinHairStyle = static_cast(strtoul(row[15], nullptr, 10)); - e.LuclinHairColor = static_cast(strtoul(row[16], nullptr, 10)); - e.LuclinEyeColor = static_cast(strtoul(row[17], nullptr, 10)); - e.LuclinEyeColor2 = static_cast(strtoul(row[18], nullptr, 10)); - e.LuclinBeardColor = static_cast(strtoul(row[19], nullptr, 10)); - e.LuclinBeard = static_cast(strtoul(row[20], nullptr, 10)); - e.DrakkinHeritage = static_cast(strtoul(row[21], nullptr, 10)); - e.DrakkinTattoo = static_cast(strtoul(row[22], nullptr, 10)); - e.DrakkinDetails = static_cast(strtoul(row[23], nullptr, 10)); + e.TemplateID = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.SuspendedTime = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.IsSuspended = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.TimerRemaining = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.Gender = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.MercSize = row[9] ? strtof(row[9], nullptr) : 5; + e.StanceID = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.HP = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.Mana = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.Endurance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.Face = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.LuclinHairStyle = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 1; + e.LuclinHairColor = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 1; + e.LuclinEyeColor = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 1; + e.LuclinEyeColor2 = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; + e.LuclinBeardColor = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 1; + e.LuclinBeard = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.DrakkinHeritage = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.DrakkinTattoo = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.DrakkinDetails = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -549,6 +548,108 @@ public: return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); } + static std::string BaseReplace() + { + return fmt::format( + "REPLACE INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static int ReplaceOne( + Database& db, + const Mercs &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.MercID)); + v.push_back(std::to_string(e.OwnerCharacterID)); + v.push_back(std::to_string(e.Slot)); + v.push_back("'" + Strings::Escape(e.Name) + "'"); + v.push_back(std::to_string(e.TemplateID)); + v.push_back(std::to_string(e.SuspendedTime)); + v.push_back(std::to_string(e.IsSuspended)); + v.push_back(std::to_string(e.TimerRemaining)); + v.push_back(std::to_string(e.Gender)); + v.push_back(std::to_string(e.MercSize)); + v.push_back(std::to_string(e.StanceID)); + v.push_back(std::to_string(e.HP)); + v.push_back(std::to_string(e.Mana)); + v.push_back(std::to_string(e.Endurance)); + v.push_back(std::to_string(e.Face)); + v.push_back(std::to_string(e.LuclinHairStyle)); + v.push_back(std::to_string(e.LuclinHairColor)); + v.push_back(std::to_string(e.LuclinEyeColor)); + v.push_back(std::to_string(e.LuclinEyeColor2)); + v.push_back(std::to_string(e.LuclinBeardColor)); + v.push_back(std::to_string(e.LuclinBeard)); + v.push_back(std::to_string(e.DrakkinHeritage)); + v.push_back(std::to_string(e.DrakkinTattoo)); + v.push_back(std::to_string(e.DrakkinDetails)); + + 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.MercID)); + v.push_back(std::to_string(e.OwnerCharacterID)); + v.push_back(std::to_string(e.Slot)); + v.push_back("'" + Strings::Escape(e.Name) + "'"); + v.push_back(std::to_string(e.TemplateID)); + v.push_back(std::to_string(e.SuspendedTime)); + v.push_back(std::to_string(e.IsSuspended)); + v.push_back(std::to_string(e.TimerRemaining)); + v.push_back(std::to_string(e.Gender)); + v.push_back(std::to_string(e.MercSize)); + v.push_back(std::to_string(e.StanceID)); + v.push_back(std::to_string(e.HP)); + v.push_back(std::to_string(e.Mana)); + v.push_back(std::to_string(e.Endurance)); + v.push_back(std::to_string(e.Face)); + v.push_back(std::to_string(e.LuclinHairStyle)); + v.push_back(std::to_string(e.LuclinHairColor)); + v.push_back(std::to_string(e.LuclinEyeColor)); + v.push_back(std::to_string(e.LuclinEyeColor2)); + v.push_back(std::to_string(e.LuclinBeardColor)); + v.push_back(std::to_string(e.LuclinBeard)); + v.push_back(std::to_string(e.DrakkinHeritage)); + v.push_back(std::to_string(e.DrakkinTattoo)); + v.push_back(std::to_string(e.DrakkinDetails)); + + 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_MERCS_REPOSITORY_H diff --git a/common/repositories/base/base_name_filter_repository.h b/common/repositories/base/base_name_filter_repository.h index 24125c098..9c3c6c4f3 100644 --- a/common/repositories/base/base_name_filter_repository.h +++ b/common/repositories/base/base_name_filter_repository.h @@ -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_NAME_FILTER_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), name_filter_id ) ); @@ -327,6 +328,64 @@ 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 NameFilter &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.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 &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.name) + "'"); + + 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_NAME_FILTER_REPOSITORY_H diff --git a/common/repositories/base/base_npc_emotes_repository.h b/common/repositories/base/base_npc_emotes_repository.h index 438ffbdf4..2812b47b2 100644 --- a/common/repositories/base/base_npc_emotes_repository.h +++ b/common/repositories/base/base_npc_emotes_repository.h @@ -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_NPC_EMOTES_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseNpcEmotesRepository { public: struct NpcEmotes { @@ -133,7 +132,7 @@ public: NpcEmotes e{}; e.id = static_cast(atoi(row[0])); - e.emoteid = static_cast(strtoul(row[1], nullptr, 10)); + e.emoteid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_ = static_cast(atoi(row[2])); e.type = static_cast(atoi(row[3])); e.text = row[4] ? row[4] : ""; @@ -268,7 +267,7 @@ public: NpcEmotes e{}; e.id = static_cast(atoi(row[0])); - e.emoteid = static_cast(strtoul(row[1], nullptr, 10)); + e.emoteid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_ = static_cast(atoi(row[2])); e.type = static_cast(atoi(row[3])); e.text = row[4] ? row[4] : ""; @@ -297,7 +296,7 @@ public: NpcEmotes e{}; e.id = static_cast(atoi(row[0])); - e.emoteid = static_cast(strtoul(row[1], nullptr, 10)); + e.emoteid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.event_ = static_cast(atoi(row[2])); e.type = static_cast(atoi(row[3])); e.text = row[4] ? row[4] : ""; @@ -359,6 +358,70 @@ 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 NpcEmotes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.emoteid)); + v.push_back(std::to_string(e.event_)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.text) + "'"); + + 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(std::to_string(e.emoteid)); + v.push_back(std::to_string(e.event_)); + v.push_back(std::to_string(e.type)); + v.push_back("'" + Strings::Escape(e.text) + "'"); + + 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_NPC_EMOTES_REPOSITORY_H diff --git a/common/repositories/base/base_npc_faction_entries_repository.h b/common/repositories/base/base_npc_faction_entries_repository.h index 44a24a00e..a77f96f89 100644 --- a/common/repositories/base/base_npc_faction_entries_repository.h +++ b/common/repositories/base/base_npc_faction_entries_repository.h @@ -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_NPC_FACTION_ENTRIES_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_faction_entries_id ) ); @@ -130,8 +131,8 @@ public: if (results.RowCount() == 1) { NpcFactionEntries e{}; - e.npc_faction_id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.npc_faction_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.value = static_cast(atoi(row[2])); e.npc_value = static_cast(atoi(row[3])); e.temp = static_cast(atoi(row[4])); @@ -266,8 +267,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcFactionEntries e{}; - e.npc_faction_id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.npc_faction_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.value = static_cast(atoi(row[2])); e.npc_value = static_cast(atoi(row[3])); e.temp = static_cast(atoi(row[4])); @@ -295,8 +296,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcFactionEntries e{}; - e.npc_faction_id = static_cast(strtoul(row[0], nullptr, 10)); - e.faction_id = static_cast(strtoul(row[1], nullptr, 10)); + e.npc_faction_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.faction_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.value = static_cast(atoi(row[2])); e.npc_value = static_cast(atoi(row[3])); e.temp = static_cast(atoi(row[4])); @@ -358,6 +359,70 @@ 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 NpcFactionEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.npc_faction_id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.value)); + v.push_back(std::to_string(e.npc_value)); + v.push_back(std::to_string(e.temp)); + + 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.npc_faction_id)); + v.push_back(std::to_string(e.faction_id)); + v.push_back(std::to_string(e.value)); + v.push_back(std::to_string(e.npc_value)); + v.push_back(std::to_string(e.temp)); + + 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_NPC_FACTION_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_npc_faction_repository.h b/common/repositories/base/base_npc_faction_repository.h index 8c2f87f04..1b7e2d709 100644 --- a/common/repositories/base/base_npc_faction_repository.h +++ b/common/repositories/base/base_npc_faction_repository.h @@ -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_NPC_FACTION_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_faction_id ) ); @@ -347,6 +348,68 @@ 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 NpcFaction &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.primaryfaction)); + v.push_back(std::to_string(e.ignore_primary_assist)); + + 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.name) + "'"); + v.push_back(std::to_string(e.primaryfaction)); + v.push_back(std::to_string(e.ignore_primary_assist)); + + 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_NPC_FACTION_REPOSITORY_H diff --git a/common/repositories/base/base_npc_scale_global_base_repository.h b/common/repositories/base/base_npc_scale_global_base_repository.h index 4920ed708..0ea0920e4 100644 --- a/common/repositories/base/base_npc_scale_global_base_repository.h +++ b/common/repositories/base/base_npc_scale_global_base_repository.h @@ -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_NPC_SCALE_GLOBAL_BASE_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseNpcScaleGlobalBaseRepository { public: struct NpcScaleGlobalBase { @@ -249,7 +248,7 @@ public: e.zone_id_list = row[2] ? row[2] : ""; e.instance_version_list = row[3] ? row[3] : ""; e.ac = static_cast(atoi(row[4])); - e.hp = strtoll(row[5], nullptr, 10); + e.hp = row[5] ? strtoll(row[5], nullptr, 10) : 0; e.accuracy = static_cast(atoi(row[6])); e.slow_mitigation = static_cast(atoi(row[7])); e.attack = static_cast(atoi(row[8])); @@ -269,12 +268,12 @@ public: e.physical_resist = static_cast(atoi(row[22])); e.min_dmg = static_cast(atoi(row[23])); e.max_dmg = static_cast(atoi(row[24])); - e.hp_regen_rate = strtoll(row[25], nullptr, 10); - e.hp_regen_per_second = strtoll(row[26], nullptr, 10); + e.hp_regen_rate = row[25] ? strtoll(row[25], nullptr, 10) : 0; + e.hp_regen_per_second = row[26] ? strtoll(row[26], nullptr, 10) : 0; e.attack_delay = static_cast(atoi(row[27])); e.spell_scale = static_cast(atoi(row[28])); e.heal_scale = static_cast(atoi(row[29])); - e.avoidance = static_cast(strtoul(row[30], nullptr, 10)); + e.avoidance = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; e.heroic_strikethrough = static_cast(atoi(row[31])); e.special_abilities = row[32] ? row[32] : ""; @@ -497,7 +496,7 @@ public: e.zone_id_list = row[2] ? row[2] : ""; e.instance_version_list = row[3] ? row[3] : ""; e.ac = static_cast(atoi(row[4])); - e.hp = strtoll(row[5], nullptr, 10); + e.hp = row[5] ? strtoll(row[5], nullptr, 10) : 0; e.accuracy = static_cast(atoi(row[6])); e.slow_mitigation = static_cast(atoi(row[7])); e.attack = static_cast(atoi(row[8])); @@ -517,12 +516,12 @@ public: e.physical_resist = static_cast(atoi(row[22])); e.min_dmg = static_cast(atoi(row[23])); e.max_dmg = static_cast(atoi(row[24])); - e.hp_regen_rate = strtoll(row[25], nullptr, 10); - e.hp_regen_per_second = strtoll(row[26], nullptr, 10); + e.hp_regen_rate = row[25] ? strtoll(row[25], nullptr, 10) : 0; + e.hp_regen_per_second = row[26] ? strtoll(row[26], nullptr, 10) : 0; e.attack_delay = static_cast(atoi(row[27])); e.spell_scale = static_cast(atoi(row[28])); e.heal_scale = static_cast(atoi(row[29])); - e.avoidance = static_cast(strtoul(row[30], nullptr, 10)); + e.avoidance = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; e.heroic_strikethrough = static_cast(atoi(row[31])); e.special_abilities = row[32] ? row[32] : ""; @@ -554,7 +553,7 @@ public: e.zone_id_list = row[2] ? row[2] : ""; e.instance_version_list = row[3] ? row[3] : ""; e.ac = static_cast(atoi(row[4])); - e.hp = strtoll(row[5], nullptr, 10); + e.hp = row[5] ? strtoll(row[5], nullptr, 10) : 0; e.accuracy = static_cast(atoi(row[6])); e.slow_mitigation = static_cast(atoi(row[7])); e.attack = static_cast(atoi(row[8])); @@ -574,12 +573,12 @@ public: e.physical_resist = static_cast(atoi(row[22])); e.min_dmg = static_cast(atoi(row[23])); e.max_dmg = static_cast(atoi(row[24])); - e.hp_regen_rate = strtoll(row[25], nullptr, 10); - e.hp_regen_per_second = strtoll(row[26], nullptr, 10); + e.hp_regen_rate = row[25] ? strtoll(row[25], nullptr, 10) : 0; + e.hp_regen_per_second = row[26] ? strtoll(row[26], nullptr, 10) : 0; e.attack_delay = static_cast(atoi(row[27])); e.spell_scale = static_cast(atoi(row[28])); e.heal_scale = static_cast(atoi(row[29])); - e.avoidance = static_cast(strtoul(row[30], nullptr, 10)); + e.avoidance = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; e.heroic_strikethrough = static_cast(atoi(row[31])); e.special_abilities = row[32] ? row[32] : ""; @@ -640,6 +639,126 @@ 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 NpcScaleGlobalBase &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.level)); + v.push_back("'" + Strings::Escape(e.zone_id_list) + "'"); + v.push_back("'" + Strings::Escape(e.instance_version_list) + "'"); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.slow_mitigation)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.strength)); + v.push_back(std::to_string(e.stamina)); + v.push_back(std::to_string(e.dexterity)); + v.push_back(std::to_string(e.agility)); + v.push_back(std::to_string(e.intelligence)); + v.push_back(std::to_string(e.wisdom)); + v.push_back(std::to_string(e.charisma)); + v.push_back(std::to_string(e.magic_resist)); + v.push_back(std::to_string(e.cold_resist)); + v.push_back(std::to_string(e.fire_resist)); + v.push_back(std::to_string(e.poison_resist)); + v.push_back(std::to_string(e.disease_resist)); + v.push_back(std::to_string(e.corruption_resist)); + v.push_back(std::to_string(e.physical_resist)); + v.push_back(std::to_string(e.min_dmg)); + v.push_back(std::to_string(e.max_dmg)); + v.push_back(std::to_string(e.hp_regen_rate)); + v.push_back(std::to_string(e.hp_regen_per_second)); + v.push_back(std::to_string(e.attack_delay)); + v.push_back(std::to_string(e.spell_scale)); + v.push_back(std::to_string(e.heal_scale)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.heroic_strikethrough)); + v.push_back("'" + Strings::Escape(e.special_abilities) + "'"); + + 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.type)); + v.push_back(std::to_string(e.level)); + v.push_back("'" + Strings::Escape(e.zone_id_list) + "'"); + v.push_back("'" + Strings::Escape(e.instance_version_list) + "'"); + v.push_back(std::to_string(e.ac)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.accuracy)); + v.push_back(std::to_string(e.slow_mitigation)); + v.push_back(std::to_string(e.attack)); + v.push_back(std::to_string(e.strength)); + v.push_back(std::to_string(e.stamina)); + v.push_back(std::to_string(e.dexterity)); + v.push_back(std::to_string(e.agility)); + v.push_back(std::to_string(e.intelligence)); + v.push_back(std::to_string(e.wisdom)); + v.push_back(std::to_string(e.charisma)); + v.push_back(std::to_string(e.magic_resist)); + v.push_back(std::to_string(e.cold_resist)); + v.push_back(std::to_string(e.fire_resist)); + v.push_back(std::to_string(e.poison_resist)); + v.push_back(std::to_string(e.disease_resist)); + v.push_back(std::to_string(e.corruption_resist)); + v.push_back(std::to_string(e.physical_resist)); + v.push_back(std::to_string(e.min_dmg)); + v.push_back(std::to_string(e.max_dmg)); + v.push_back(std::to_string(e.hp_regen_rate)); + v.push_back(std::to_string(e.hp_regen_per_second)); + v.push_back(std::to_string(e.attack_delay)); + v.push_back(std::to_string(e.spell_scale)); + v.push_back(std::to_string(e.heal_scale)); + v.push_back(std::to_string(e.avoidance)); + v.push_back(std::to_string(e.heroic_strikethrough)); + v.push_back("'" + Strings::Escape(e.special_abilities) + "'"); + + 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_NPC_SCALE_GLOBAL_BASE_REPOSITORY_H diff --git a/common/repositories/base/base_npc_spells_effects_entries_repository.h b/common/repositories/base/base_npc_spells_effects_entries_repository.h index 257b5ffc7..cce837a80 100644 --- a/common/repositories/base/base_npc_spells_effects_entries_repository.h +++ b/common/repositories/base/base_npc_spells_effects_entries_repository.h @@ -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_NPC_SPELLS_EFFECTS_ENTRIES_REPOSITORY_H @@ -132,8 +132,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_spells_effects_entries_id ) ); @@ -142,11 +143,11 @@ public: if (results.RowCount() == 1) { NpcSpellsEffectsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_effects_id = static_cast(atoi(row[1])); e.spell_effect_id = static_cast(atoi(row[2])); - e.minlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.minlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.maxlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 255; e.se_base = static_cast(atoi(row[5])); e.se_limit = static_cast(atoi(row[6])); e.se_max = static_cast(atoi(row[7])); @@ -289,11 +290,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEffectsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_effects_id = static_cast(atoi(row[1])); e.spell_effect_id = static_cast(atoi(row[2])); - e.minlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.minlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.maxlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 255; e.se_base = static_cast(atoi(row[5])); e.se_limit = static_cast(atoi(row[6])); e.se_max = static_cast(atoi(row[7])); @@ -321,11 +322,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEffectsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_effects_id = static_cast(atoi(row[1])); e.spell_effect_id = static_cast(atoi(row[2])); - e.minlevel = static_cast(strtoul(row[3], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[4], nullptr, 10)); + e.minlevel = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.maxlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 255; e.se_base = static_cast(atoi(row[5])); e.se_limit = static_cast(atoi(row[6])); e.se_max = static_cast(atoi(row[7])); @@ -387,6 +388,76 @@ 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 NpcSpellsEffectsEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.npc_spells_effects_id)); + v.push_back(std::to_string(e.spell_effect_id)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.se_base)); + v.push_back(std::to_string(e.se_limit)); + v.push_back(std::to_string(e.se_max)); + + 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(std::to_string(e.npc_spells_effects_id)); + v.push_back(std::to_string(e.spell_effect_id)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.se_base)); + v.push_back(std::to_string(e.se_limit)); + v.push_back(std::to_string(e.se_max)); + + 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_NPC_SPELLS_EFFECTS_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_npc_spells_effects_repository.h b/common/repositories/base/base_npc_spells_effects_repository.h index 333dc615c..b425c42c8 100644 --- a/common/repositories/base/base_npc_spells_effects_repository.h +++ b/common/repositories/base/base_npc_spells_effects_repository.h @@ -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_NPC_SPELLS_EFFECTS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_spells_effects_id ) ); @@ -122,9 +123,9 @@ public: if (results.RowCount() == 1) { NpcSpellsEffects e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -249,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEffects e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -276,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEffects e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -337,6 +338,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 NpcSpellsEffects &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.parent_list)); + + 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.name) + "'"); + v.push_back(std::to_string(e.parent_list)); + + 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_NPC_SPELLS_EFFECTS_REPOSITORY_H diff --git a/common/repositories/base/base_npc_spells_entries_repository.h b/common/repositories/base/base_npc_spells_entries_repository.h index 1b946a24a..282c285c3 100644 --- a/common/repositories/base/base_npc_spells_entries_repository.h +++ b/common/repositories/base/base_npc_spells_entries_repository.h @@ -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_NPC_SPELLS_ENTRIES_REPOSITORY_H @@ -148,8 +148,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_spells_entries_id ) ); @@ -158,12 +159,12 @@ public: if (results.RowCount() == 1) { NpcSpellsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_id = static_cast(atoi(row[1])); - e.spellid = static_cast(strtoul(row[2], nullptr, 10)); - e.type = static_cast(strtoul(row[3], nullptr, 10)); - e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.spellid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.type = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.minlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.maxlevel = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 255; e.manacost = static_cast(atoi(row[6])); e.recast_delay = static_cast(atoi(row[7])); e.priority = static_cast(atoi(row[8])); @@ -321,12 +322,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_id = static_cast(atoi(row[1])); - e.spellid = static_cast(strtoul(row[2], nullptr, 10)); - e.type = static_cast(strtoul(row[3], nullptr, 10)); - e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.spellid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.type = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.minlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.maxlevel = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 255; e.manacost = static_cast(atoi(row[6])); e.recast_delay = static_cast(atoi(row[7])); e.priority = static_cast(atoi(row[8])); @@ -357,12 +358,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpellsEntries e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.npc_spells_id = static_cast(atoi(row[1])); - e.spellid = static_cast(strtoul(row[2], nullptr, 10)); - e.type = static_cast(strtoul(row[3], nullptr, 10)); - e.minlevel = static_cast(strtoul(row[4], nullptr, 10)); - e.maxlevel = static_cast(strtoul(row[5], nullptr, 10)); + e.spellid = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.type = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.minlevel = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.maxlevel = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 255; e.manacost = static_cast(atoi(row[6])); e.recast_delay = static_cast(atoi(row[7])); e.priority = static_cast(atoi(row[8])); @@ -427,6 +428,84 @@ 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 NpcSpellsEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.manacost)); + v.push_back(std::to_string(e.recast_delay)); + v.push_back(std::to_string(e.priority)); + v.push_back(std::to_string(e.resist_adjust)); + v.push_back(std::to_string(e.min_hp)); + v.push_back(std::to_string(e.max_hp)); + + 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(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.spellid)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.minlevel)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.manacost)); + v.push_back(std::to_string(e.recast_delay)); + v.push_back(std::to_string(e.priority)); + v.push_back(std::to_string(e.resist_adjust)); + v.push_back(std::to_string(e.min_hp)); + v.push_back(std::to_string(e.max_hp)); + + 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_NPC_SPELLS_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_npc_spells_repository.h b/common/repositories/base/base_npc_spells_repository.h index 576333a1d..2cd2cdc2f 100644 --- a/common/repositories/base/base_npc_spells_repository.h +++ b/common/repositories/base/base_npc_spells_repository.h @@ -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_NPC_SPELLS_REPOSITORY_H @@ -184,8 +184,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_spells_id ) ); @@ -194,27 +195,27 @@ public: if (results.RowCount() == 1) { NpcSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.attack_proc = static_cast(atoi(row[3])); e.proc_chance = static_cast(atoi(row[4])); e.range_proc = static_cast(atoi(row[5])); e.rproc_chance = static_cast(atoi(row[6])); e.defensive_proc = static_cast(atoi(row[7])); e.dproc_chance = static_cast(atoi(row[8])); - e.fail_recast = static_cast(strtoul(row[9], nullptr, 10)); - e.engaged_no_sp_recast_min = static_cast(strtoul(row[10], nullptr, 10)); - e.engaged_no_sp_recast_max = static_cast(strtoul(row[11], nullptr, 10)); - e.engaged_b_self_chance = static_cast(strtoul(row[12], nullptr, 10)); - e.engaged_b_other_chance = static_cast(strtoul(row[13], nullptr, 10)); - e.engaged_d_chance = static_cast(strtoul(row[14], nullptr, 10)); - e.pursue_no_sp_recast_min = static_cast(strtoul(row[15], nullptr, 10)); - e.pursue_no_sp_recast_max = static_cast(strtoul(row[16], nullptr, 10)); - e.pursue_d_chance = static_cast(strtoul(row[17], nullptr, 10)); - e.idle_no_sp_recast_min = static_cast(strtoul(row[18], nullptr, 10)); - e.idle_no_sp_recast_max = static_cast(strtoul(row[19], nullptr, 10)); - e.idle_b_chance = static_cast(strtoul(row[20], nullptr, 10)); + e.fail_recast = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.engaged_no_sp_recast_min = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.engaged_no_sp_recast_max = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.engaged_b_self_chance = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.engaged_b_other_chance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.engaged_d_chance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.pursue_no_sp_recast_min = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.pursue_no_sp_recast_max = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.pursue_d_chance = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.idle_no_sp_recast_min = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.idle_no_sp_recast_max = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.idle_b_chance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; return e; } @@ -393,27 +394,27 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.attack_proc = static_cast(atoi(row[3])); e.proc_chance = static_cast(atoi(row[4])); e.range_proc = static_cast(atoi(row[5])); e.rproc_chance = static_cast(atoi(row[6])); e.defensive_proc = static_cast(atoi(row[7])); e.dproc_chance = static_cast(atoi(row[8])); - e.fail_recast = static_cast(strtoul(row[9], nullptr, 10)); - e.engaged_no_sp_recast_min = static_cast(strtoul(row[10], nullptr, 10)); - e.engaged_no_sp_recast_max = static_cast(strtoul(row[11], nullptr, 10)); - e.engaged_b_self_chance = static_cast(strtoul(row[12], nullptr, 10)); - e.engaged_b_other_chance = static_cast(strtoul(row[13], nullptr, 10)); - e.engaged_d_chance = static_cast(strtoul(row[14], nullptr, 10)); - e.pursue_no_sp_recast_min = static_cast(strtoul(row[15], nullptr, 10)); - e.pursue_no_sp_recast_max = static_cast(strtoul(row[16], nullptr, 10)); - e.pursue_d_chance = static_cast(strtoul(row[17], nullptr, 10)); - e.idle_no_sp_recast_min = static_cast(strtoul(row[18], nullptr, 10)); - e.idle_no_sp_recast_max = static_cast(strtoul(row[19], nullptr, 10)); - e.idle_b_chance = static_cast(strtoul(row[20], nullptr, 10)); + e.fail_recast = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.engaged_no_sp_recast_min = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.engaged_no_sp_recast_max = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.engaged_b_self_chance = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.engaged_b_other_chance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.engaged_d_chance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.pursue_no_sp_recast_min = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.pursue_no_sp_recast_max = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.pursue_d_chance = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.idle_no_sp_recast_min = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.idle_no_sp_recast_max = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.idle_b_chance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -438,27 +439,27 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcSpells e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.parent_list = static_cast(strtoul(row[2], nullptr, 10)); + e.parent_list = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.attack_proc = static_cast(atoi(row[3])); e.proc_chance = static_cast(atoi(row[4])); e.range_proc = static_cast(atoi(row[5])); e.rproc_chance = static_cast(atoi(row[6])); e.defensive_proc = static_cast(atoi(row[7])); e.dproc_chance = static_cast(atoi(row[8])); - e.fail_recast = static_cast(strtoul(row[9], nullptr, 10)); - e.engaged_no_sp_recast_min = static_cast(strtoul(row[10], nullptr, 10)); - e.engaged_no_sp_recast_max = static_cast(strtoul(row[11], nullptr, 10)); - e.engaged_b_self_chance = static_cast(strtoul(row[12], nullptr, 10)); - e.engaged_b_other_chance = static_cast(strtoul(row[13], nullptr, 10)); - e.engaged_d_chance = static_cast(strtoul(row[14], nullptr, 10)); - e.pursue_no_sp_recast_min = static_cast(strtoul(row[15], nullptr, 10)); - e.pursue_no_sp_recast_max = static_cast(strtoul(row[16], nullptr, 10)); - e.pursue_d_chance = static_cast(strtoul(row[17], nullptr, 10)); - e.idle_no_sp_recast_min = static_cast(strtoul(row[18], nullptr, 10)); - e.idle_no_sp_recast_max = static_cast(strtoul(row[19], nullptr, 10)); - e.idle_b_chance = static_cast(strtoul(row[20], nullptr, 10)); + e.fail_recast = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.engaged_no_sp_recast_min = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.engaged_no_sp_recast_max = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.engaged_b_self_chance = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.engaged_b_other_chance = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.engaged_d_chance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.pursue_no_sp_recast_min = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.pursue_no_sp_recast_max = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.pursue_d_chance = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.idle_no_sp_recast_min = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.idle_no_sp_recast_max = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.idle_b_chance = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -517,6 +518,102 @@ 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 NpcSpells &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.parent_list)); + v.push_back(std::to_string(e.attack_proc)); + v.push_back(std::to_string(e.proc_chance)); + v.push_back(std::to_string(e.range_proc)); + v.push_back(std::to_string(e.rproc_chance)); + v.push_back(std::to_string(e.defensive_proc)); + v.push_back(std::to_string(e.dproc_chance)); + v.push_back(std::to_string(e.fail_recast)); + v.push_back(std::to_string(e.engaged_no_sp_recast_min)); + v.push_back(std::to_string(e.engaged_no_sp_recast_max)); + v.push_back(std::to_string(e.engaged_b_self_chance)); + v.push_back(std::to_string(e.engaged_b_other_chance)); + v.push_back(std::to_string(e.engaged_d_chance)); + v.push_back(std::to_string(e.pursue_no_sp_recast_min)); + v.push_back(std::to_string(e.pursue_no_sp_recast_max)); + v.push_back(std::to_string(e.pursue_d_chance)); + v.push_back(std::to_string(e.idle_no_sp_recast_min)); + v.push_back(std::to_string(e.idle_no_sp_recast_max)); + v.push_back(std::to_string(e.idle_b_chance)); + + 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.name) + "'"); + v.push_back(std::to_string(e.parent_list)); + v.push_back(std::to_string(e.attack_proc)); + v.push_back(std::to_string(e.proc_chance)); + v.push_back(std::to_string(e.range_proc)); + v.push_back(std::to_string(e.rproc_chance)); + v.push_back(std::to_string(e.defensive_proc)); + v.push_back(std::to_string(e.dproc_chance)); + v.push_back(std::to_string(e.fail_recast)); + v.push_back(std::to_string(e.engaged_no_sp_recast_min)); + v.push_back(std::to_string(e.engaged_no_sp_recast_max)); + v.push_back(std::to_string(e.engaged_b_self_chance)); + v.push_back(std::to_string(e.engaged_b_other_chance)); + v.push_back(std::to_string(e.engaged_d_chance)); + v.push_back(std::to_string(e.pursue_no_sp_recast_min)); + v.push_back(std::to_string(e.pursue_no_sp_recast_max)); + v.push_back(std::to_string(e.pursue_d_chance)); + v.push_back(std::to_string(e.idle_no_sp_recast_min)); + v.push_back(std::to_string(e.idle_no_sp_recast_max)); + v.push_back(std::to_string(e.idle_b_chance)); + + 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_NPC_SPELLS_REPOSITORY_H diff --git a/common/repositories/base/base_npc_types_repository.h b/common/repositories/base/base_npc_types_repository.h index 42e1f0ee3..38f99bce1 100644 --- a/common/repositories/base/base_npc_types_repository.h +++ b/common/repositories/base/base_npc_types_repository.h @@ -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_NPC_TYPES_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseNpcTypesRepository { public: struct NpcTypes { @@ -623,79 +622,79 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.lastname = row[2] ? row[2] : ""; - e.level = static_cast(strtoul(row[3], nullptr, 10)); - e.race = static_cast(strtoul(row[4], nullptr, 10)); - e.class_ = static_cast(strtoul(row[5], nullptr, 10)); + e.level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.race = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.class_ = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.bodytype = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.gender = static_cast(strtoul(row[9], nullptr, 10)); - e.texture = static_cast(strtoul(row[10], nullptr, 10)); - e.helmtexture = static_cast(strtoul(row[11], nullptr, 10)); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.gender = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.texture = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.helmtexture = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.herosforgemodel = static_cast(atoi(row[12])); - e.size = strtof(row[13], nullptr); - e.hp_regen_rate = strtoll(row[14], nullptr, 10); - e.hp_regen_per_second = strtoll(row[15], nullptr, 10); - e.mana_regen_rate = strtoll(row[16], nullptr, 10); - e.loottable_id = static_cast(strtoul(row[17], nullptr, 10)); - e.merchant_id = static_cast(strtoul(row[18], nullptr, 10)); - e.alt_currency_id = static_cast(strtoul(row[19], nullptr, 10)); - e.npc_spells_id = static_cast(strtoul(row[20], nullptr, 10)); - e.npc_spells_effects_id = static_cast(strtoul(row[21], nullptr, 10)); + e.size = row[13] ? strtof(row[13], nullptr) : 0; + e.hp_regen_rate = row[14] ? strtoll(row[14], nullptr, 10) : 0; + e.hp_regen_per_second = row[15] ? strtoll(row[15], nullptr, 10) : 0; + e.mana_regen_rate = row[16] ? strtoll(row[16], nullptr, 10) : 0; + e.loottable_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.merchant_id = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.alt_currency_id = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.npc_spells_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.npc_spells_effects_id = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; e.npc_faction_id = static_cast(atoi(row[22])); - e.adventure_template_id = static_cast(strtoul(row[23], nullptr, 10)); - e.trap_template = static_cast(strtoul(row[24], nullptr, 10)); - e.mindmg = static_cast(strtoul(row[25], nullptr, 10)); - e.maxdmg = static_cast(strtoul(row[26], nullptr, 10)); + e.adventure_template_id = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.trap_template = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.mindmg = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.maxdmg = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; e.attack_count = static_cast(atoi(row[27])); e.npcspecialattks = row[28] ? row[28] : ""; e.special_abilities = row[29] ? row[29] : ""; - e.aggroradius = static_cast(strtoul(row[30], nullptr, 10)); - e.assistradius = static_cast(strtoul(row[31], nullptr, 10)); - e.face = static_cast(strtoul(row[32], nullptr, 10)); - e.luclin_hairstyle = static_cast(strtoul(row[33], nullptr, 10)); - e.luclin_haircolor = static_cast(strtoul(row[34], nullptr, 10)); - e.luclin_eyecolor = static_cast(strtoul(row[35], nullptr, 10)); - e.luclin_eyecolor2 = static_cast(strtoul(row[36], nullptr, 10)); - e.luclin_beardcolor = static_cast(strtoul(row[37], nullptr, 10)); - e.luclin_beard = static_cast(strtoul(row[38], nullptr, 10)); + e.aggroradius = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.assistradius = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.face = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 1; + e.luclin_hairstyle = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 1; + e.luclin_haircolor = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 1; + e.luclin_eyecolor = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 1; + e.luclin_eyecolor2 = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 1; + e.luclin_beardcolor = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 1; + e.luclin_beard = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; e.drakkin_heritage = static_cast(atoi(row[39])); e.drakkin_tattoo = static_cast(atoi(row[40])); e.drakkin_details = static_cast(atoi(row[41])); - e.armortint_id = static_cast(strtoul(row[42], nullptr, 10)); - e.armortint_red = static_cast(strtoul(row[43], nullptr, 10)); - e.armortint_green = static_cast(strtoul(row[44], nullptr, 10)); - e.armortint_blue = static_cast(strtoul(row[45], nullptr, 10)); - e.d_melee_texture1 = static_cast(strtoul(row[46], nullptr, 10)); - e.d_melee_texture2 = static_cast(strtoul(row[47], nullptr, 10)); + e.armortint_id = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.armortint_red = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.armortint_green = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.armortint_blue = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.d_melee_texture1 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.d_melee_texture2 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; e.ammo_idfile = row[48] ? row[48] : ""; - e.prim_melee_type = static_cast(strtoul(row[49], nullptr, 10)); - e.sec_melee_type = static_cast(strtoul(row[50], nullptr, 10)); - e.ranged_type = static_cast(strtoul(row[51], nullptr, 10)); - e.runspeed = strtof(row[52], nullptr); + e.prim_melee_type = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 28; + e.sec_melee_type = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 28; + e.ranged_type = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 7; + e.runspeed = row[52] ? strtof(row[52], nullptr) : 0; e.MR = static_cast(atoi(row[53])); e.CR = static_cast(atoi(row[54])); e.DR = static_cast(atoi(row[55])); e.FR = static_cast(atoi(row[56])); e.PR = static_cast(atoi(row[57])); e.Corrup = static_cast(atoi(row[58])); - e.PhR = static_cast(strtoul(row[59], nullptr, 10)); + e.PhR = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; e.see_invis = static_cast(atoi(row[60])); e.see_invis_undead = static_cast(atoi(row[61])); - e.qglobal = static_cast(strtoul(row[62], nullptr, 10)); + e.qglobal = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; e.AC = static_cast(atoi(row[63])); e.npc_aggro = static_cast(atoi(row[64])); e.spawn_limit = static_cast(atoi(row[65])); - e.attack_speed = strtof(row[66], nullptr); - e.attack_delay = static_cast(strtoul(row[67], nullptr, 10)); + e.attack_speed = row[66] ? strtof(row[66], nullptr) : 0; + e.attack_delay = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 30; e.findable = static_cast(atoi(row[68])); - e.STR = static_cast(strtoul(row[69], nullptr, 10)); - e.STA = static_cast(strtoul(row[70], nullptr, 10)); - e.DEX = static_cast(strtoul(row[71], nullptr, 10)); - e.AGI = static_cast(strtoul(row[72], nullptr, 10)); - e._INT = static_cast(strtoul(row[73], nullptr, 10)); - e.WIS = static_cast(strtoul(row[74], nullptr, 10)); - e.CHA = static_cast(strtoul(row[75], nullptr, 10)); + e.STR = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 75; + e.STA = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 75; + e.DEX = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 75; + e.AGI = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 75; + e._INT = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 80; + e.WIS = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 75; + e.CHA = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 75; e.see_hide = static_cast(atoi(row[76])); e.see_improved_hide = static_cast(atoi(row[77])); e.trackable = static_cast(atoi(row[78])); @@ -703,20 +702,20 @@ public: e.exclude = static_cast(atoi(row[80])); e.ATK = static_cast(atoi(row[81])); e.Accuracy = static_cast(atoi(row[82])); - e.Avoidance = static_cast(strtoul(row[83], nullptr, 10)); + e.Avoidance = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; e.slow_mitigation = static_cast(atoi(row[84])); - e.version = static_cast(strtoul(row[85], nullptr, 10)); + e.version = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; e.maxlevel = static_cast(atoi(row[86])); e.scalerate = static_cast(atoi(row[87])); - e.private_corpse = static_cast(strtoul(row[88], nullptr, 10)); - e.unique_spawn_by_name = static_cast(strtoul(row[89], nullptr, 10)); - e.underwater = static_cast(strtoul(row[90], nullptr, 10)); + e.private_corpse = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.unique_spawn_by_name = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.underwater = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; e.isquest = static_cast(atoi(row[91])); - e.emoteid = static_cast(strtoul(row[92], nullptr, 10)); - e.spellscale = strtof(row[93], nullptr); - e.healscale = strtof(row[94], nullptr); - e.no_target_hotkey = static_cast(strtoul(row[95], nullptr, 10)); - e.raid_target = static_cast(strtoul(row[96], nullptr, 10)); + e.emoteid = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; + e.spellscale = row[93] ? strtof(row[93], nullptr) : 100; + e.healscale = row[94] ? strtof(row[94], nullptr) : 100; + e.no_target_hotkey = row[95] ? static_cast(strtoul(row[95], nullptr, 10)) : 0; + e.raid_target = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; e.armtexture = static_cast(atoi(row[97])); e.bracertexture = static_cast(atoi(row[98])); e.handtexture = static_cast(atoi(row[99])); @@ -746,7 +745,7 @@ public: e.exp_mod = static_cast(atoi(row[123])); e.heroic_strikethrough = static_cast(atoi(row[124])); e.faction_amount = static_cast(atoi(row[125])); - e.keeps_sold_items = static_cast(strtoul(row[126], nullptr, 10)); + e.keeps_sold_items = row[126] ? static_cast(strtoul(row[126], nullptr, 10)) : 1; return e; } @@ -1246,79 +1245,79 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.lastname = row[2] ? row[2] : ""; - e.level = static_cast(strtoul(row[3], nullptr, 10)); - e.race = static_cast(strtoul(row[4], nullptr, 10)); - e.class_ = static_cast(strtoul(row[5], nullptr, 10)); + e.level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.race = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.class_ = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.bodytype = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.gender = static_cast(strtoul(row[9], nullptr, 10)); - e.texture = static_cast(strtoul(row[10], nullptr, 10)); - e.helmtexture = static_cast(strtoul(row[11], nullptr, 10)); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.gender = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.texture = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.helmtexture = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.herosforgemodel = static_cast(atoi(row[12])); - e.size = strtof(row[13], nullptr); - e.hp_regen_rate = strtoll(row[14], nullptr, 10); - e.hp_regen_per_second = strtoll(row[15], nullptr, 10); - e.mana_regen_rate = strtoll(row[16], nullptr, 10); - e.loottable_id = static_cast(strtoul(row[17], nullptr, 10)); - e.merchant_id = static_cast(strtoul(row[18], nullptr, 10)); - e.alt_currency_id = static_cast(strtoul(row[19], nullptr, 10)); - e.npc_spells_id = static_cast(strtoul(row[20], nullptr, 10)); - e.npc_spells_effects_id = static_cast(strtoul(row[21], nullptr, 10)); + e.size = row[13] ? strtof(row[13], nullptr) : 0; + e.hp_regen_rate = row[14] ? strtoll(row[14], nullptr, 10) : 0; + e.hp_regen_per_second = row[15] ? strtoll(row[15], nullptr, 10) : 0; + e.mana_regen_rate = row[16] ? strtoll(row[16], nullptr, 10) : 0; + e.loottable_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.merchant_id = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.alt_currency_id = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.npc_spells_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.npc_spells_effects_id = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; e.npc_faction_id = static_cast(atoi(row[22])); - e.adventure_template_id = static_cast(strtoul(row[23], nullptr, 10)); - e.trap_template = static_cast(strtoul(row[24], nullptr, 10)); - e.mindmg = static_cast(strtoul(row[25], nullptr, 10)); - e.maxdmg = static_cast(strtoul(row[26], nullptr, 10)); + e.adventure_template_id = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.trap_template = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.mindmg = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.maxdmg = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; e.attack_count = static_cast(atoi(row[27])); e.npcspecialattks = row[28] ? row[28] : ""; e.special_abilities = row[29] ? row[29] : ""; - e.aggroradius = static_cast(strtoul(row[30], nullptr, 10)); - e.assistradius = static_cast(strtoul(row[31], nullptr, 10)); - e.face = static_cast(strtoul(row[32], nullptr, 10)); - e.luclin_hairstyle = static_cast(strtoul(row[33], nullptr, 10)); - e.luclin_haircolor = static_cast(strtoul(row[34], nullptr, 10)); - e.luclin_eyecolor = static_cast(strtoul(row[35], nullptr, 10)); - e.luclin_eyecolor2 = static_cast(strtoul(row[36], nullptr, 10)); - e.luclin_beardcolor = static_cast(strtoul(row[37], nullptr, 10)); - e.luclin_beard = static_cast(strtoul(row[38], nullptr, 10)); + e.aggroradius = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.assistradius = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.face = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 1; + e.luclin_hairstyle = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 1; + e.luclin_haircolor = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 1; + e.luclin_eyecolor = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 1; + e.luclin_eyecolor2 = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 1; + e.luclin_beardcolor = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 1; + e.luclin_beard = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; e.drakkin_heritage = static_cast(atoi(row[39])); e.drakkin_tattoo = static_cast(atoi(row[40])); e.drakkin_details = static_cast(atoi(row[41])); - e.armortint_id = static_cast(strtoul(row[42], nullptr, 10)); - e.armortint_red = static_cast(strtoul(row[43], nullptr, 10)); - e.armortint_green = static_cast(strtoul(row[44], nullptr, 10)); - e.armortint_blue = static_cast(strtoul(row[45], nullptr, 10)); - e.d_melee_texture1 = static_cast(strtoul(row[46], nullptr, 10)); - e.d_melee_texture2 = static_cast(strtoul(row[47], nullptr, 10)); + e.armortint_id = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.armortint_red = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.armortint_green = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.armortint_blue = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.d_melee_texture1 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.d_melee_texture2 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; e.ammo_idfile = row[48] ? row[48] : ""; - e.prim_melee_type = static_cast(strtoul(row[49], nullptr, 10)); - e.sec_melee_type = static_cast(strtoul(row[50], nullptr, 10)); - e.ranged_type = static_cast(strtoul(row[51], nullptr, 10)); - e.runspeed = strtof(row[52], nullptr); + e.prim_melee_type = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 28; + e.sec_melee_type = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 28; + e.ranged_type = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 7; + e.runspeed = row[52] ? strtof(row[52], nullptr) : 0; e.MR = static_cast(atoi(row[53])); e.CR = static_cast(atoi(row[54])); e.DR = static_cast(atoi(row[55])); e.FR = static_cast(atoi(row[56])); e.PR = static_cast(atoi(row[57])); e.Corrup = static_cast(atoi(row[58])); - e.PhR = static_cast(strtoul(row[59], nullptr, 10)); + e.PhR = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; e.see_invis = static_cast(atoi(row[60])); e.see_invis_undead = static_cast(atoi(row[61])); - e.qglobal = static_cast(strtoul(row[62], nullptr, 10)); + e.qglobal = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; e.AC = static_cast(atoi(row[63])); e.npc_aggro = static_cast(atoi(row[64])); e.spawn_limit = static_cast(atoi(row[65])); - e.attack_speed = strtof(row[66], nullptr); - e.attack_delay = static_cast(strtoul(row[67], nullptr, 10)); + e.attack_speed = row[66] ? strtof(row[66], nullptr) : 0; + e.attack_delay = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 30; e.findable = static_cast(atoi(row[68])); - e.STR = static_cast(strtoul(row[69], nullptr, 10)); - e.STA = static_cast(strtoul(row[70], nullptr, 10)); - e.DEX = static_cast(strtoul(row[71], nullptr, 10)); - e.AGI = static_cast(strtoul(row[72], nullptr, 10)); - e._INT = static_cast(strtoul(row[73], nullptr, 10)); - e.WIS = static_cast(strtoul(row[74], nullptr, 10)); - e.CHA = static_cast(strtoul(row[75], nullptr, 10)); + e.STR = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 75; + e.STA = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 75; + e.DEX = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 75; + e.AGI = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 75; + e._INT = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 80; + e.WIS = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 75; + e.CHA = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 75; e.see_hide = static_cast(atoi(row[76])); e.see_improved_hide = static_cast(atoi(row[77])); e.trackable = static_cast(atoi(row[78])); @@ -1326,20 +1325,20 @@ public: e.exclude = static_cast(atoi(row[80])); e.ATK = static_cast(atoi(row[81])); e.Accuracy = static_cast(atoi(row[82])); - e.Avoidance = static_cast(strtoul(row[83], nullptr, 10)); + e.Avoidance = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; e.slow_mitigation = static_cast(atoi(row[84])); - e.version = static_cast(strtoul(row[85], nullptr, 10)); + e.version = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; e.maxlevel = static_cast(atoi(row[86])); e.scalerate = static_cast(atoi(row[87])); - e.private_corpse = static_cast(strtoul(row[88], nullptr, 10)); - e.unique_spawn_by_name = static_cast(strtoul(row[89], nullptr, 10)); - e.underwater = static_cast(strtoul(row[90], nullptr, 10)); + e.private_corpse = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.unique_spawn_by_name = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.underwater = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; e.isquest = static_cast(atoi(row[91])); - e.emoteid = static_cast(strtoul(row[92], nullptr, 10)); - e.spellscale = strtof(row[93], nullptr); - e.healscale = strtof(row[94], nullptr); - e.no_target_hotkey = static_cast(strtoul(row[95], nullptr, 10)); - e.raid_target = static_cast(strtoul(row[96], nullptr, 10)); + e.emoteid = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; + e.spellscale = row[93] ? strtof(row[93], nullptr) : 100; + e.healscale = row[94] ? strtof(row[94], nullptr) : 100; + e.no_target_hotkey = row[95] ? static_cast(strtoul(row[95], nullptr, 10)) : 0; + e.raid_target = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; e.armtexture = static_cast(atoi(row[97])); e.bracertexture = static_cast(atoi(row[98])); e.handtexture = static_cast(atoi(row[99])); @@ -1369,7 +1368,7 @@ public: e.exp_mod = static_cast(atoi(row[123])); e.heroic_strikethrough = static_cast(atoi(row[124])); e.faction_amount = static_cast(atoi(row[125])); - e.keeps_sold_items = static_cast(strtoul(row[126], nullptr, 10)); + e.keeps_sold_items = row[126] ? static_cast(strtoul(row[126], nullptr, 10)) : 1; all_entries.push_back(e); } @@ -1397,79 +1396,79 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.lastname = row[2] ? row[2] : ""; - e.level = static_cast(strtoul(row[3], nullptr, 10)); - e.race = static_cast(strtoul(row[4], nullptr, 10)); - e.class_ = static_cast(strtoul(row[5], nullptr, 10)); + e.level = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.race = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.class_ = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; e.bodytype = static_cast(atoi(row[6])); - e.hp = strtoll(row[7], nullptr, 10); - e.mana = strtoll(row[8], nullptr, 10); - e.gender = static_cast(strtoul(row[9], nullptr, 10)); - e.texture = static_cast(strtoul(row[10], nullptr, 10)); - e.helmtexture = static_cast(strtoul(row[11], nullptr, 10)); + e.hp = row[7] ? strtoll(row[7], nullptr, 10) : 0; + e.mana = row[8] ? strtoll(row[8], nullptr, 10) : 0; + e.gender = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.texture = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.helmtexture = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.herosforgemodel = static_cast(atoi(row[12])); - e.size = strtof(row[13], nullptr); - e.hp_regen_rate = strtoll(row[14], nullptr, 10); - e.hp_regen_per_second = strtoll(row[15], nullptr, 10); - e.mana_regen_rate = strtoll(row[16], nullptr, 10); - e.loottable_id = static_cast(strtoul(row[17], nullptr, 10)); - e.merchant_id = static_cast(strtoul(row[18], nullptr, 10)); - e.alt_currency_id = static_cast(strtoul(row[19], nullptr, 10)); - e.npc_spells_id = static_cast(strtoul(row[20], nullptr, 10)); - e.npc_spells_effects_id = static_cast(strtoul(row[21], nullptr, 10)); + e.size = row[13] ? strtof(row[13], nullptr) : 0; + e.hp_regen_rate = row[14] ? strtoll(row[14], nullptr, 10) : 0; + e.hp_regen_per_second = row[15] ? strtoll(row[15], nullptr, 10) : 0; + e.mana_regen_rate = row[16] ? strtoll(row[16], nullptr, 10) : 0; + e.loottable_id = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.merchant_id = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.alt_currency_id = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.npc_spells_id = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.npc_spells_effects_id = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; e.npc_faction_id = static_cast(atoi(row[22])); - e.adventure_template_id = static_cast(strtoul(row[23], nullptr, 10)); - e.trap_template = static_cast(strtoul(row[24], nullptr, 10)); - e.mindmg = static_cast(strtoul(row[25], nullptr, 10)); - e.maxdmg = static_cast(strtoul(row[26], nullptr, 10)); + e.adventure_template_id = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.trap_template = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.mindmg = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.maxdmg = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; e.attack_count = static_cast(atoi(row[27])); e.npcspecialattks = row[28] ? row[28] : ""; e.special_abilities = row[29] ? row[29] : ""; - e.aggroradius = static_cast(strtoul(row[30], nullptr, 10)); - e.assistradius = static_cast(strtoul(row[31], nullptr, 10)); - e.face = static_cast(strtoul(row[32], nullptr, 10)); - e.luclin_hairstyle = static_cast(strtoul(row[33], nullptr, 10)); - e.luclin_haircolor = static_cast(strtoul(row[34], nullptr, 10)); - e.luclin_eyecolor = static_cast(strtoul(row[35], nullptr, 10)); - e.luclin_eyecolor2 = static_cast(strtoul(row[36], nullptr, 10)); - e.luclin_beardcolor = static_cast(strtoul(row[37], nullptr, 10)); - e.luclin_beard = static_cast(strtoul(row[38], nullptr, 10)); + e.aggroradius = row[30] ? static_cast(strtoul(row[30], nullptr, 10)) : 0; + e.assistradius = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 0; + e.face = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 1; + e.luclin_hairstyle = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 1; + e.luclin_haircolor = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 1; + e.luclin_eyecolor = row[35] ? static_cast(strtoul(row[35], nullptr, 10)) : 1; + e.luclin_eyecolor2 = row[36] ? static_cast(strtoul(row[36], nullptr, 10)) : 1; + e.luclin_beardcolor = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 1; + e.luclin_beard = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; e.drakkin_heritage = static_cast(atoi(row[39])); e.drakkin_tattoo = static_cast(atoi(row[40])); e.drakkin_details = static_cast(atoi(row[41])); - e.armortint_id = static_cast(strtoul(row[42], nullptr, 10)); - e.armortint_red = static_cast(strtoul(row[43], nullptr, 10)); - e.armortint_green = static_cast(strtoul(row[44], nullptr, 10)); - e.armortint_blue = static_cast(strtoul(row[45], nullptr, 10)); - e.d_melee_texture1 = static_cast(strtoul(row[46], nullptr, 10)); - e.d_melee_texture2 = static_cast(strtoul(row[47], nullptr, 10)); + e.armortint_id = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.armortint_red = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.armortint_green = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.armortint_blue = row[45] ? static_cast(strtoul(row[45], nullptr, 10)) : 0; + e.d_melee_texture1 = row[46] ? static_cast(strtoul(row[46], nullptr, 10)) : 0; + e.d_melee_texture2 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; e.ammo_idfile = row[48] ? row[48] : ""; - e.prim_melee_type = static_cast(strtoul(row[49], nullptr, 10)); - e.sec_melee_type = static_cast(strtoul(row[50], nullptr, 10)); - e.ranged_type = static_cast(strtoul(row[51], nullptr, 10)); - e.runspeed = strtof(row[52], nullptr); + e.prim_melee_type = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 28; + e.sec_melee_type = row[50] ? static_cast(strtoul(row[50], nullptr, 10)) : 28; + e.ranged_type = row[51] ? static_cast(strtoul(row[51], nullptr, 10)) : 7; + e.runspeed = row[52] ? strtof(row[52], nullptr) : 0; e.MR = static_cast(atoi(row[53])); e.CR = static_cast(atoi(row[54])); e.DR = static_cast(atoi(row[55])); e.FR = static_cast(atoi(row[56])); e.PR = static_cast(atoi(row[57])); e.Corrup = static_cast(atoi(row[58])); - e.PhR = static_cast(strtoul(row[59], nullptr, 10)); + e.PhR = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; e.see_invis = static_cast(atoi(row[60])); e.see_invis_undead = static_cast(atoi(row[61])); - e.qglobal = static_cast(strtoul(row[62], nullptr, 10)); + e.qglobal = row[62] ? static_cast(strtoul(row[62], nullptr, 10)) : 0; e.AC = static_cast(atoi(row[63])); e.npc_aggro = static_cast(atoi(row[64])); e.spawn_limit = static_cast(atoi(row[65])); - e.attack_speed = strtof(row[66], nullptr); - e.attack_delay = static_cast(strtoul(row[67], nullptr, 10)); + e.attack_speed = row[66] ? strtof(row[66], nullptr) : 0; + e.attack_delay = row[67] ? static_cast(strtoul(row[67], nullptr, 10)) : 30; e.findable = static_cast(atoi(row[68])); - e.STR = static_cast(strtoul(row[69], nullptr, 10)); - e.STA = static_cast(strtoul(row[70], nullptr, 10)); - e.DEX = static_cast(strtoul(row[71], nullptr, 10)); - e.AGI = static_cast(strtoul(row[72], nullptr, 10)); - e._INT = static_cast(strtoul(row[73], nullptr, 10)); - e.WIS = static_cast(strtoul(row[74], nullptr, 10)); - e.CHA = static_cast(strtoul(row[75], nullptr, 10)); + e.STR = row[69] ? static_cast(strtoul(row[69], nullptr, 10)) : 75; + e.STA = row[70] ? static_cast(strtoul(row[70], nullptr, 10)) : 75; + e.DEX = row[71] ? static_cast(strtoul(row[71], nullptr, 10)) : 75; + e.AGI = row[72] ? static_cast(strtoul(row[72], nullptr, 10)) : 75; + e._INT = row[73] ? static_cast(strtoul(row[73], nullptr, 10)) : 80; + e.WIS = row[74] ? static_cast(strtoul(row[74], nullptr, 10)) : 75; + e.CHA = row[75] ? static_cast(strtoul(row[75], nullptr, 10)) : 75; e.see_hide = static_cast(atoi(row[76])); e.see_improved_hide = static_cast(atoi(row[77])); e.trackable = static_cast(atoi(row[78])); @@ -1477,20 +1476,20 @@ public: e.exclude = static_cast(atoi(row[80])); e.ATK = static_cast(atoi(row[81])); e.Accuracy = static_cast(atoi(row[82])); - e.Avoidance = static_cast(strtoul(row[83], nullptr, 10)); + e.Avoidance = row[83] ? static_cast(strtoul(row[83], nullptr, 10)) : 0; e.slow_mitigation = static_cast(atoi(row[84])); - e.version = static_cast(strtoul(row[85], nullptr, 10)); + e.version = row[85] ? static_cast(strtoul(row[85], nullptr, 10)) : 0; e.maxlevel = static_cast(atoi(row[86])); e.scalerate = static_cast(atoi(row[87])); - e.private_corpse = static_cast(strtoul(row[88], nullptr, 10)); - e.unique_spawn_by_name = static_cast(strtoul(row[89], nullptr, 10)); - e.underwater = static_cast(strtoul(row[90], nullptr, 10)); + e.private_corpse = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 0; + e.unique_spawn_by_name = row[89] ? static_cast(strtoul(row[89], nullptr, 10)) : 0; + e.underwater = row[90] ? static_cast(strtoul(row[90], nullptr, 10)) : 0; e.isquest = static_cast(atoi(row[91])); - e.emoteid = static_cast(strtoul(row[92], nullptr, 10)); - e.spellscale = strtof(row[93], nullptr); - e.healscale = strtof(row[94], nullptr); - e.no_target_hotkey = static_cast(strtoul(row[95], nullptr, 10)); - e.raid_target = static_cast(strtoul(row[96], nullptr, 10)); + e.emoteid = row[92] ? static_cast(strtoul(row[92], nullptr, 10)) : 0; + e.spellscale = row[93] ? strtof(row[93], nullptr) : 100; + e.healscale = row[94] ? strtof(row[94], nullptr) : 100; + e.no_target_hotkey = row[95] ? static_cast(strtoul(row[95], nullptr, 10)) : 0; + e.raid_target = row[96] ? static_cast(strtoul(row[96], nullptr, 10)) : 0; e.armtexture = static_cast(atoi(row[97])); e.bracertexture = static_cast(atoi(row[98])); e.handtexture = static_cast(atoi(row[99])); @@ -1520,7 +1519,7 @@ public: e.exp_mod = static_cast(atoi(row[123])); e.heroic_strikethrough = static_cast(atoi(row[124])); e.faction_amount = static_cast(atoi(row[125])); - e.keeps_sold_items = static_cast(strtoul(row[126], nullptr, 10)); + e.keeps_sold_items = row[126] ? static_cast(strtoul(row[126], nullptr, 10)) : 1; all_entries.push_back(e); } @@ -1579,6 +1578,314 @@ 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 NpcTypes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.lastname) + "'"); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.bodytype)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helmtexture)); + v.push_back(std::to_string(e.herosforgemodel)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.hp_regen_rate)); + v.push_back(std::to_string(e.hp_regen_per_second)); + v.push_back(std::to_string(e.mana_regen_rate)); + v.push_back(std::to_string(e.loottable_id)); + v.push_back(std::to_string(e.merchant_id)); + v.push_back(std::to_string(e.alt_currency_id)); + v.push_back(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.npc_spells_effects_id)); + v.push_back(std::to_string(e.npc_faction_id)); + v.push_back(std::to_string(e.adventure_template_id)); + v.push_back(std::to_string(e.trap_template)); + v.push_back(std::to_string(e.mindmg)); + v.push_back(std::to_string(e.maxdmg)); + v.push_back(std::to_string(e.attack_count)); + v.push_back("'" + Strings::Escape(e.npcspecialattks) + "'"); + v.push_back("'" + Strings::Escape(e.special_abilities) + "'"); + v.push_back(std::to_string(e.aggroradius)); + v.push_back(std::to_string(e.assistradius)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.luclin_hairstyle)); + v.push_back(std::to_string(e.luclin_haircolor)); + v.push_back(std::to_string(e.luclin_eyecolor)); + v.push_back(std::to_string(e.luclin_eyecolor2)); + v.push_back(std::to_string(e.luclin_beardcolor)); + v.push_back(std::to_string(e.luclin_beard)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.armortint_id)); + v.push_back(std::to_string(e.armortint_red)); + v.push_back(std::to_string(e.armortint_green)); + v.push_back(std::to_string(e.armortint_blue)); + v.push_back(std::to_string(e.d_melee_texture1)); + v.push_back(std::to_string(e.d_melee_texture2)); + v.push_back("'" + Strings::Escape(e.ammo_idfile) + "'"); + v.push_back(std::to_string(e.prim_melee_type)); + v.push_back(std::to_string(e.sec_melee_type)); + v.push_back(std::to_string(e.ranged_type)); + v.push_back(std::to_string(e.runspeed)); + v.push_back(std::to_string(e.MR)); + v.push_back(std::to_string(e.CR)); + v.push_back(std::to_string(e.DR)); + v.push_back(std::to_string(e.FR)); + v.push_back(std::to_string(e.PR)); + v.push_back(std::to_string(e.Corrup)); + v.push_back(std::to_string(e.PhR)); + v.push_back(std::to_string(e.see_invis)); + v.push_back(std::to_string(e.see_invis_undead)); + v.push_back(std::to_string(e.qglobal)); + v.push_back(std::to_string(e.AC)); + v.push_back(std::to_string(e.npc_aggro)); + v.push_back(std::to_string(e.spawn_limit)); + v.push_back(std::to_string(e.attack_speed)); + v.push_back(std::to_string(e.attack_delay)); + v.push_back(std::to_string(e.findable)); + v.push_back(std::to_string(e.STR)); + v.push_back(std::to_string(e.STA)); + v.push_back(std::to_string(e.DEX)); + v.push_back(std::to_string(e.AGI)); + v.push_back(std::to_string(e._INT)); + v.push_back(std::to_string(e.WIS)); + v.push_back(std::to_string(e.CHA)); + v.push_back(std::to_string(e.see_hide)); + v.push_back(std::to_string(e.see_improved_hide)); + v.push_back(std::to_string(e.trackable)); + v.push_back(std::to_string(e.isbot)); + v.push_back(std::to_string(e.exclude)); + v.push_back(std::to_string(e.ATK)); + v.push_back(std::to_string(e.Accuracy)); + v.push_back(std::to_string(e.Avoidance)); + v.push_back(std::to_string(e.slow_mitigation)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.scalerate)); + v.push_back(std::to_string(e.private_corpse)); + v.push_back(std::to_string(e.unique_spawn_by_name)); + v.push_back(std::to_string(e.underwater)); + v.push_back(std::to_string(e.isquest)); + v.push_back(std::to_string(e.emoteid)); + v.push_back(std::to_string(e.spellscale)); + v.push_back(std::to_string(e.healscale)); + v.push_back(std::to_string(e.no_target_hotkey)); + v.push_back(std::to_string(e.raid_target)); + v.push_back(std::to_string(e.armtexture)); + v.push_back(std::to_string(e.bracertexture)); + v.push_back(std::to_string(e.handtexture)); + v.push_back(std::to_string(e.legtexture)); + v.push_back(std::to_string(e.feettexture)); + v.push_back(std::to_string(e.light)); + v.push_back(std::to_string(e.walkspeed)); + v.push_back(std::to_string(e.peqid)); + v.push_back(std::to_string(e.unique_)); + v.push_back(std::to_string(e.fixed)); + v.push_back(std::to_string(e.ignore_despawn)); + v.push_back(std::to_string(e.show_name)); + v.push_back(std::to_string(e.untargetable)); + v.push_back(std::to_string(e.charm_ac)); + v.push_back(std::to_string(e.charm_min_dmg)); + v.push_back(std::to_string(e.charm_max_dmg)); + v.push_back(std::to_string(e.charm_attack_delay)); + v.push_back(std::to_string(e.charm_accuracy_rating)); + v.push_back(std::to_string(e.charm_avoidance_rating)); + v.push_back(std::to_string(e.charm_atk)); + v.push_back(std::to_string(e.skip_global_loot)); + v.push_back(std::to_string(e.rare_spawn)); + v.push_back(std::to_string(e.stuck_behavior)); + v.push_back(std::to_string(e.model)); + v.push_back(std::to_string(e.flymode)); + v.push_back(std::to_string(e.always_aggro)); + v.push_back(std::to_string(e.exp_mod)); + v.push_back(std::to_string(e.heroic_strikethrough)); + v.push_back(std::to_string(e.faction_amount)); + v.push_back(std::to_string(e.keeps_sold_items)); + + 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.name) + "'"); + v.push_back("'" + Strings::Escape(e.lastname) + "'"); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.race)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.bodytype)); + v.push_back(std::to_string(e.hp)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helmtexture)); + v.push_back(std::to_string(e.herosforgemodel)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.hp_regen_rate)); + v.push_back(std::to_string(e.hp_regen_per_second)); + v.push_back(std::to_string(e.mana_regen_rate)); + v.push_back(std::to_string(e.loottable_id)); + v.push_back(std::to_string(e.merchant_id)); + v.push_back(std::to_string(e.alt_currency_id)); + v.push_back(std::to_string(e.npc_spells_id)); + v.push_back(std::to_string(e.npc_spells_effects_id)); + v.push_back(std::to_string(e.npc_faction_id)); + v.push_back(std::to_string(e.adventure_template_id)); + v.push_back(std::to_string(e.trap_template)); + v.push_back(std::to_string(e.mindmg)); + v.push_back(std::to_string(e.maxdmg)); + v.push_back(std::to_string(e.attack_count)); + v.push_back("'" + Strings::Escape(e.npcspecialattks) + "'"); + v.push_back("'" + Strings::Escape(e.special_abilities) + "'"); + v.push_back(std::to_string(e.aggroradius)); + v.push_back(std::to_string(e.assistradius)); + v.push_back(std::to_string(e.face)); + v.push_back(std::to_string(e.luclin_hairstyle)); + v.push_back(std::to_string(e.luclin_haircolor)); + v.push_back(std::to_string(e.luclin_eyecolor)); + v.push_back(std::to_string(e.luclin_eyecolor2)); + v.push_back(std::to_string(e.luclin_beardcolor)); + v.push_back(std::to_string(e.luclin_beard)); + v.push_back(std::to_string(e.drakkin_heritage)); + v.push_back(std::to_string(e.drakkin_tattoo)); + v.push_back(std::to_string(e.drakkin_details)); + v.push_back(std::to_string(e.armortint_id)); + v.push_back(std::to_string(e.armortint_red)); + v.push_back(std::to_string(e.armortint_green)); + v.push_back(std::to_string(e.armortint_blue)); + v.push_back(std::to_string(e.d_melee_texture1)); + v.push_back(std::to_string(e.d_melee_texture2)); + v.push_back("'" + Strings::Escape(e.ammo_idfile) + "'"); + v.push_back(std::to_string(e.prim_melee_type)); + v.push_back(std::to_string(e.sec_melee_type)); + v.push_back(std::to_string(e.ranged_type)); + v.push_back(std::to_string(e.runspeed)); + v.push_back(std::to_string(e.MR)); + v.push_back(std::to_string(e.CR)); + v.push_back(std::to_string(e.DR)); + v.push_back(std::to_string(e.FR)); + v.push_back(std::to_string(e.PR)); + v.push_back(std::to_string(e.Corrup)); + v.push_back(std::to_string(e.PhR)); + v.push_back(std::to_string(e.see_invis)); + v.push_back(std::to_string(e.see_invis_undead)); + v.push_back(std::to_string(e.qglobal)); + v.push_back(std::to_string(e.AC)); + v.push_back(std::to_string(e.npc_aggro)); + v.push_back(std::to_string(e.spawn_limit)); + v.push_back(std::to_string(e.attack_speed)); + v.push_back(std::to_string(e.attack_delay)); + v.push_back(std::to_string(e.findable)); + v.push_back(std::to_string(e.STR)); + v.push_back(std::to_string(e.STA)); + v.push_back(std::to_string(e.DEX)); + v.push_back(std::to_string(e.AGI)); + v.push_back(std::to_string(e._INT)); + v.push_back(std::to_string(e.WIS)); + v.push_back(std::to_string(e.CHA)); + v.push_back(std::to_string(e.see_hide)); + v.push_back(std::to_string(e.see_improved_hide)); + v.push_back(std::to_string(e.trackable)); + v.push_back(std::to_string(e.isbot)); + v.push_back(std::to_string(e.exclude)); + v.push_back(std::to_string(e.ATK)); + v.push_back(std::to_string(e.Accuracy)); + v.push_back(std::to_string(e.Avoidance)); + v.push_back(std::to_string(e.slow_mitigation)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.maxlevel)); + v.push_back(std::to_string(e.scalerate)); + v.push_back(std::to_string(e.private_corpse)); + v.push_back(std::to_string(e.unique_spawn_by_name)); + v.push_back(std::to_string(e.underwater)); + v.push_back(std::to_string(e.isquest)); + v.push_back(std::to_string(e.emoteid)); + v.push_back(std::to_string(e.spellscale)); + v.push_back(std::to_string(e.healscale)); + v.push_back(std::to_string(e.no_target_hotkey)); + v.push_back(std::to_string(e.raid_target)); + v.push_back(std::to_string(e.armtexture)); + v.push_back(std::to_string(e.bracertexture)); + v.push_back(std::to_string(e.handtexture)); + v.push_back(std::to_string(e.legtexture)); + v.push_back(std::to_string(e.feettexture)); + v.push_back(std::to_string(e.light)); + v.push_back(std::to_string(e.walkspeed)); + v.push_back(std::to_string(e.peqid)); + v.push_back(std::to_string(e.unique_)); + v.push_back(std::to_string(e.fixed)); + v.push_back(std::to_string(e.ignore_despawn)); + v.push_back(std::to_string(e.show_name)); + v.push_back(std::to_string(e.untargetable)); + v.push_back(std::to_string(e.charm_ac)); + v.push_back(std::to_string(e.charm_min_dmg)); + v.push_back(std::to_string(e.charm_max_dmg)); + v.push_back(std::to_string(e.charm_attack_delay)); + v.push_back(std::to_string(e.charm_accuracy_rating)); + v.push_back(std::to_string(e.charm_avoidance_rating)); + v.push_back(std::to_string(e.charm_atk)); + v.push_back(std::to_string(e.skip_global_loot)); + v.push_back(std::to_string(e.rare_spawn)); + v.push_back(std::to_string(e.stuck_behavior)); + v.push_back(std::to_string(e.model)); + v.push_back(std::to_string(e.flymode)); + v.push_back(std::to_string(e.always_aggro)); + v.push_back(std::to_string(e.exp_mod)); + v.push_back(std::to_string(e.heroic_strikethrough)); + v.push_back(std::to_string(e.faction_amount)); + v.push_back(std::to_string(e.keeps_sold_items)); + + 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_NPC_TYPES_REPOSITORY_H diff --git a/common/repositories/base/base_npc_types_tint_repository.h b/common/repositories/base/base_npc_types_tint_repository.h index 3a4361fa1..f7d02b9bc 100644 --- a/common/repositories/base/base_npc_types_tint_repository.h +++ b/common/repositories/base/base_npc_types_tint_repository.h @@ -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_NPC_TYPES_TINT_REPOSITORY_H @@ -216,8 +216,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), npc_types_tint_id ) ); @@ -226,35 +227,35 @@ public: if (results.RowCount() == 1) { NpcTypesTint e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.tint_set_name = row[1] ? row[1] : ""; - e.red1h = static_cast(strtoul(row[2], nullptr, 10)); - e.grn1h = static_cast(strtoul(row[3], nullptr, 10)); - e.blu1h = static_cast(strtoul(row[4], nullptr, 10)); - e.red2c = static_cast(strtoul(row[5], nullptr, 10)); - e.grn2c = static_cast(strtoul(row[6], nullptr, 10)); - e.blu2c = static_cast(strtoul(row[7], nullptr, 10)); - e.red3a = static_cast(strtoul(row[8], nullptr, 10)); - e.grn3a = static_cast(strtoul(row[9], nullptr, 10)); - e.blu3a = static_cast(strtoul(row[10], nullptr, 10)); - e.red4b = static_cast(strtoul(row[11], nullptr, 10)); - e.grn4b = static_cast(strtoul(row[12], nullptr, 10)); - e.blu4b = static_cast(strtoul(row[13], nullptr, 10)); - e.red5g = static_cast(strtoul(row[14], nullptr, 10)); - e.grn5g = static_cast(strtoul(row[15], nullptr, 10)); - e.blu5g = static_cast(strtoul(row[16], nullptr, 10)); - e.red6l = static_cast(strtoul(row[17], nullptr, 10)); - e.grn6l = static_cast(strtoul(row[18], nullptr, 10)); - e.blu6l = static_cast(strtoul(row[19], nullptr, 10)); - e.red7f = static_cast(strtoul(row[20], nullptr, 10)); - e.grn7f = static_cast(strtoul(row[21], nullptr, 10)); - e.blu7f = static_cast(strtoul(row[22], nullptr, 10)); - e.red8x = static_cast(strtoul(row[23], nullptr, 10)); - e.grn8x = static_cast(strtoul(row[24], nullptr, 10)); - e.blu8x = static_cast(strtoul(row[25], nullptr, 10)); - e.red9x = static_cast(strtoul(row[26], nullptr, 10)); - e.grn9x = static_cast(strtoul(row[27], nullptr, 10)); - e.blu9x = static_cast(strtoul(row[28], nullptr, 10)); + e.red1h = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.grn1h = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.blu1h = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.red2c = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.grn2c = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.blu2c = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.red3a = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.grn3a = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.blu3a = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.red4b = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.grn4b = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.blu4b = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.red5g = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.grn5g = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.blu5g = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.red6l = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.grn6l = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.blu6l = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.red7f = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.grn7f = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.blu7f = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.red8x = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.grn8x = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.blu8x = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.red9x = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.grn9x = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.blu9x = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; return e; } @@ -458,35 +459,35 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcTypesTint e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.tint_set_name = row[1] ? row[1] : ""; - e.red1h = static_cast(strtoul(row[2], nullptr, 10)); - e.grn1h = static_cast(strtoul(row[3], nullptr, 10)); - e.blu1h = static_cast(strtoul(row[4], nullptr, 10)); - e.red2c = static_cast(strtoul(row[5], nullptr, 10)); - e.grn2c = static_cast(strtoul(row[6], nullptr, 10)); - e.blu2c = static_cast(strtoul(row[7], nullptr, 10)); - e.red3a = static_cast(strtoul(row[8], nullptr, 10)); - e.grn3a = static_cast(strtoul(row[9], nullptr, 10)); - e.blu3a = static_cast(strtoul(row[10], nullptr, 10)); - e.red4b = static_cast(strtoul(row[11], nullptr, 10)); - e.grn4b = static_cast(strtoul(row[12], nullptr, 10)); - e.blu4b = static_cast(strtoul(row[13], nullptr, 10)); - e.red5g = static_cast(strtoul(row[14], nullptr, 10)); - e.grn5g = static_cast(strtoul(row[15], nullptr, 10)); - e.blu5g = static_cast(strtoul(row[16], nullptr, 10)); - e.red6l = static_cast(strtoul(row[17], nullptr, 10)); - e.grn6l = static_cast(strtoul(row[18], nullptr, 10)); - e.blu6l = static_cast(strtoul(row[19], nullptr, 10)); - e.red7f = static_cast(strtoul(row[20], nullptr, 10)); - e.grn7f = static_cast(strtoul(row[21], nullptr, 10)); - e.blu7f = static_cast(strtoul(row[22], nullptr, 10)); - e.red8x = static_cast(strtoul(row[23], nullptr, 10)); - e.grn8x = static_cast(strtoul(row[24], nullptr, 10)); - e.blu8x = static_cast(strtoul(row[25], nullptr, 10)); - e.red9x = static_cast(strtoul(row[26], nullptr, 10)); - e.grn9x = static_cast(strtoul(row[27], nullptr, 10)); - e.blu9x = static_cast(strtoul(row[28], nullptr, 10)); + e.red1h = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.grn1h = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.blu1h = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.red2c = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.grn2c = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.blu2c = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.red3a = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.grn3a = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.blu3a = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.red4b = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.grn4b = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.blu4b = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.red5g = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.grn5g = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.blu5g = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.red6l = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.grn6l = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.blu6l = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.red7f = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.grn7f = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.blu7f = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.red8x = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.grn8x = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.blu8x = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.red9x = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.grn9x = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.blu9x = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -511,35 +512,35 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { NpcTypesTint e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.tint_set_name = row[1] ? row[1] : ""; - e.red1h = static_cast(strtoul(row[2], nullptr, 10)); - e.grn1h = static_cast(strtoul(row[3], nullptr, 10)); - e.blu1h = static_cast(strtoul(row[4], nullptr, 10)); - e.red2c = static_cast(strtoul(row[5], nullptr, 10)); - e.grn2c = static_cast(strtoul(row[6], nullptr, 10)); - e.blu2c = static_cast(strtoul(row[7], nullptr, 10)); - e.red3a = static_cast(strtoul(row[8], nullptr, 10)); - e.grn3a = static_cast(strtoul(row[9], nullptr, 10)); - e.blu3a = static_cast(strtoul(row[10], nullptr, 10)); - e.red4b = static_cast(strtoul(row[11], nullptr, 10)); - e.grn4b = static_cast(strtoul(row[12], nullptr, 10)); - e.blu4b = static_cast(strtoul(row[13], nullptr, 10)); - e.red5g = static_cast(strtoul(row[14], nullptr, 10)); - e.grn5g = static_cast(strtoul(row[15], nullptr, 10)); - e.blu5g = static_cast(strtoul(row[16], nullptr, 10)); - e.red6l = static_cast(strtoul(row[17], nullptr, 10)); - e.grn6l = static_cast(strtoul(row[18], nullptr, 10)); - e.blu6l = static_cast(strtoul(row[19], nullptr, 10)); - e.red7f = static_cast(strtoul(row[20], nullptr, 10)); - e.grn7f = static_cast(strtoul(row[21], nullptr, 10)); - e.blu7f = static_cast(strtoul(row[22], nullptr, 10)); - e.red8x = static_cast(strtoul(row[23], nullptr, 10)); - e.grn8x = static_cast(strtoul(row[24], nullptr, 10)); - e.blu8x = static_cast(strtoul(row[25], nullptr, 10)); - e.red9x = static_cast(strtoul(row[26], nullptr, 10)); - e.grn9x = static_cast(strtoul(row[27], nullptr, 10)); - e.blu9x = static_cast(strtoul(row[28], nullptr, 10)); + e.red1h = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.grn1h = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.blu1h = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.red2c = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.grn2c = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.blu2c = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.red3a = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.grn3a = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.blu3a = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.red4b = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.grn4b = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.blu4b = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.red5g = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.grn5g = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.blu5g = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.red6l = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.grn6l = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 0; + e.blu6l = row[19] ? static_cast(strtoul(row[19], nullptr, 10)) : 0; + e.red7f = row[20] ? static_cast(strtoul(row[20], nullptr, 10)) : 0; + e.grn7f = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.blu7f = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.red8x = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.grn8x = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.blu8x = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.red9x = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.grn9x = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 0; + e.blu9x = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -598,6 +599,118 @@ 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 NpcTypesTint &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.tint_set_name) + "'"); + v.push_back(std::to_string(e.red1h)); + v.push_back(std::to_string(e.grn1h)); + v.push_back(std::to_string(e.blu1h)); + v.push_back(std::to_string(e.red2c)); + v.push_back(std::to_string(e.grn2c)); + v.push_back(std::to_string(e.blu2c)); + v.push_back(std::to_string(e.red3a)); + v.push_back(std::to_string(e.grn3a)); + v.push_back(std::to_string(e.blu3a)); + v.push_back(std::to_string(e.red4b)); + v.push_back(std::to_string(e.grn4b)); + v.push_back(std::to_string(e.blu4b)); + v.push_back(std::to_string(e.red5g)); + v.push_back(std::to_string(e.grn5g)); + v.push_back(std::to_string(e.blu5g)); + v.push_back(std::to_string(e.red6l)); + v.push_back(std::to_string(e.grn6l)); + v.push_back(std::to_string(e.blu6l)); + v.push_back(std::to_string(e.red7f)); + v.push_back(std::to_string(e.grn7f)); + v.push_back(std::to_string(e.blu7f)); + v.push_back(std::to_string(e.red8x)); + v.push_back(std::to_string(e.grn8x)); + v.push_back(std::to_string(e.blu8x)); + v.push_back(std::to_string(e.red9x)); + v.push_back(std::to_string(e.grn9x)); + v.push_back(std::to_string(e.blu9x)); + + 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.tint_set_name) + "'"); + v.push_back(std::to_string(e.red1h)); + v.push_back(std::to_string(e.grn1h)); + v.push_back(std::to_string(e.blu1h)); + v.push_back(std::to_string(e.red2c)); + v.push_back(std::to_string(e.grn2c)); + v.push_back(std::to_string(e.blu2c)); + v.push_back(std::to_string(e.red3a)); + v.push_back(std::to_string(e.grn3a)); + v.push_back(std::to_string(e.blu3a)); + v.push_back(std::to_string(e.red4b)); + v.push_back(std::to_string(e.grn4b)); + v.push_back(std::to_string(e.blu4b)); + v.push_back(std::to_string(e.red5g)); + v.push_back(std::to_string(e.grn5g)); + v.push_back(std::to_string(e.blu5g)); + v.push_back(std::to_string(e.red6l)); + v.push_back(std::to_string(e.grn6l)); + v.push_back(std::to_string(e.blu6l)); + v.push_back(std::to_string(e.red7f)); + v.push_back(std::to_string(e.grn7f)); + v.push_back(std::to_string(e.blu7f)); + v.push_back(std::to_string(e.red8x)); + v.push_back(std::to_string(e.grn8x)); + v.push_back(std::to_string(e.blu8x)); + v.push_back(std::to_string(e.red9x)); + v.push_back(std::to_string(e.grn9x)); + v.push_back(std::to_string(e.blu9x)); + + 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_NPC_TYPES_TINT_REPOSITORY_H diff --git a/common/repositories/base/base_object_contents_repository.h b/common/repositories/base/base_object_contents_repository.h index f0cf358bb..6e6af49f8 100644 --- a/common/repositories/base/base_object_contents_repository.h +++ b/common/repositories/base/base_object_contents_repository.h @@ -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_OBJECT_CONTENTS_REPOSITORY_H @@ -148,8 +148,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), object_contents_id ) ); @@ -158,17 +159,17 @@ public: if (results.RowCount() == 1) { ObjectContents e{}; - e.zoneid = static_cast(strtoul(row[0], nullptr, 10)); - e.parentid = static_cast(strtoul(row[1], nullptr, 10)); - e.bagidx = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); + e.zoneid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.parentid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bagidx = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[4])); e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); return e; @@ -322,17 +323,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { ObjectContents e{}; - e.zoneid = static_cast(strtoul(row[0], nullptr, 10)); - e.parentid = static_cast(strtoul(row[1], nullptr, 10)); - e.bagidx = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); + e.zoneid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.parentid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bagidx = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[4])); e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); all_entries.push_back(e); @@ -358,17 +359,17 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { ObjectContents e{}; - e.zoneid = static_cast(strtoul(row[0], nullptr, 10)); - e.parentid = static_cast(strtoul(row[1], nullptr, 10)); - e.bagidx = static_cast(strtoul(row[2], nullptr, 10)); - e.itemid = static_cast(strtoul(row[3], nullptr, 10)); + e.zoneid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.parentid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.bagidx = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.itemid = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[4])); e.droptime = strtoll(row[5] ? row[5] : "-1", nullptr, 10); - e.augslot1 = static_cast(strtoul(row[6], nullptr, 10)); - e.augslot2 = static_cast(strtoul(row[7], nullptr, 10)); - e.augslot3 = static_cast(strtoul(row[8], nullptr, 10)); - e.augslot4 = static_cast(strtoul(row[9], nullptr, 10)); - e.augslot5 = static_cast(strtoul(row[10], nullptr, 10)); + e.augslot1 = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.augslot2 = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.augslot3 = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.augslot4 = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.augslot5 = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.augslot6 = static_cast(atoi(row[11])); all_entries.push_back(e); @@ -428,6 +429,84 @@ 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 ObjectContents &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.parentid)); + v.push_back(std::to_string(e.bagidx)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back("FROM_UNIXTIME(" + (e.droptime > 0 ? std::to_string(e.droptime) : "null") + ")"); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + + 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.zoneid)); + v.push_back(std::to_string(e.parentid)); + v.push_back(std::to_string(e.bagidx)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back("FROM_UNIXTIME(" + (e.droptime > 0 ? std::to_string(e.droptime) : "null") + ")"); + v.push_back(std::to_string(e.augslot1)); + v.push_back(std::to_string(e.augslot2)); + v.push_back(std::to_string(e.augslot3)); + v.push_back(std::to_string(e.augslot4)); + v.push_back(std::to_string(e.augslot5)); + v.push_back(std::to_string(e.augslot6)); + + 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_OBJECT_CONTENTS_REPOSITORY_H diff --git a/common/repositories/base/base_object_repository.h b/common/repositories/base/base_object_repository.h index 1a6c894cc..29d1c16e9 100644 --- a/common/repositories/base/base_object_repository.h +++ b/common/repositories/base/base_object_repository.h @@ -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_OBJECT_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseObjectRepository { public: struct Object { @@ -33,8 +32,6 @@ public: int32_t type; int32_t icon; float size_percentage; - int32_t solid_type; - int32_t incline; int32_t unknown24; int32_t unknown60; int32_t unknown64; @@ -43,6 +40,8 @@ public: int32_t unknown76; int32_t unknown84; float size; + int32_t solid_type; + int32_t incline; float tilt_x; float tilt_y; std::string display_name; @@ -73,8 +72,6 @@ public: "type", "icon", "size_percentage", - "solid_type", - "incline", "unknown24", "unknown60", "unknown64", @@ -83,6 +80,8 @@ public: "unknown76", "unknown84", "size", + "solid_type", + "incline", "tilt_x", "tilt_y", "display_name", @@ -109,8 +108,6 @@ public: "type", "icon", "size_percentage", - "solid_type", - "incline", "unknown24", "unknown60", "unknown64", @@ -119,6 +116,8 @@ public: "unknown76", "unknown84", "size", + "solid_type", + "incline", "tilt_x", "tilt_y", "display_name", @@ -179,8 +178,6 @@ public: e.type = 0; e.icon = 0; e.size_percentage = 0; - e.solid_type = 0; - e.incline = 0; e.unknown24 = 0; e.unknown60 = 0; e.unknown64 = 0; @@ -189,6 +186,8 @@ public: e.unknown76 = 0; e.unknown84 = 0; e.size = 100; + e.solid_type = 0; + e.incline = 0; e.tilt_x = 0; e.tilt_y = 0; e.display_name = ""; @@ -233,30 +232,30 @@ public: Object e{}; e.id = static_cast(atoi(row[0])); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.xpos = strtof(row[3], nullptr); - e.ypos = strtof(row[4], nullptr); - e.zpos = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.xpos = row[3] ? strtof(row[3], nullptr) : 0; + e.ypos = row[4] ? strtof(row[4], nullptr) : 0; + e.zpos = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.itemid = static_cast(atoi(row[7])); - e.charges = static_cast(strtoul(row[8], nullptr, 10)); + e.charges = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.objectname = row[9] ? row[9] : ""; e.type = static_cast(atoi(row[10])); e.icon = static_cast(atoi(row[11])); - e.size_percentage = strtof(row[12], nullptr); - e.solid_type = static_cast(atoi(row[13])); - e.incline = static_cast(atoi(row[14])); - e.unknown24 = static_cast(atoi(row[15])); - e.unknown60 = static_cast(atoi(row[16])); - e.unknown64 = static_cast(atoi(row[17])); - e.unknown68 = static_cast(atoi(row[18])); - e.unknown72 = static_cast(atoi(row[19])); - e.unknown76 = static_cast(atoi(row[20])); - e.unknown84 = static_cast(atoi(row[21])); - e.size = strtof(row[22], nullptr); - e.tilt_x = strtof(row[23], nullptr); - e.tilt_y = strtof(row[24], nullptr); + e.size_percentage = row[12] ? strtof(row[12], nullptr) : 0; + e.unknown24 = static_cast(atoi(row[13])); + e.unknown60 = static_cast(atoi(row[14])); + e.unknown64 = static_cast(atoi(row[15])); + e.unknown68 = static_cast(atoi(row[16])); + e.unknown72 = static_cast(atoi(row[17])); + e.unknown76 = static_cast(atoi(row[18])); + e.unknown84 = static_cast(atoi(row[19])); + e.size = row[20] ? strtof(row[20], nullptr) : 100; + e.solid_type = static_cast(atoi(row[21])); + e.incline = static_cast(atoi(row[22])); + e.tilt_x = row[23] ? strtof(row[23], nullptr) : 0; + e.tilt_y = row[24] ? strtof(row[24], nullptr) : 0; e.display_name = row[25] ? row[25] : ""; e.min_expansion = static_cast(atoi(row[26])); e.max_expansion = static_cast(atoi(row[27])); @@ -307,16 +306,16 @@ public: v.push_back(columns[10] + " = " + std::to_string(e.type)); v.push_back(columns[11] + " = " + std::to_string(e.icon)); v.push_back(columns[12] + " = " + std::to_string(e.size_percentage)); - v.push_back(columns[13] + " = " + std::to_string(e.solid_type)); - v.push_back(columns[14] + " = " + std::to_string(e.incline)); - v.push_back(columns[15] + " = " + std::to_string(e.unknown24)); - v.push_back(columns[16] + " = " + std::to_string(e.unknown60)); - v.push_back(columns[17] + " = " + std::to_string(e.unknown64)); - v.push_back(columns[18] + " = " + std::to_string(e.unknown68)); - v.push_back(columns[19] + " = " + std::to_string(e.unknown72)); - v.push_back(columns[20] + " = " + std::to_string(e.unknown76)); - v.push_back(columns[21] + " = " + std::to_string(e.unknown84)); - v.push_back(columns[22] + " = " + std::to_string(e.size)); + v.push_back(columns[13] + " = " + std::to_string(e.unknown24)); + v.push_back(columns[14] + " = " + std::to_string(e.unknown60)); + v.push_back(columns[15] + " = " + std::to_string(e.unknown64)); + v.push_back(columns[16] + " = " + std::to_string(e.unknown68)); + v.push_back(columns[17] + " = " + std::to_string(e.unknown72)); + v.push_back(columns[18] + " = " + std::to_string(e.unknown76)); + v.push_back(columns[19] + " = " + std::to_string(e.unknown84)); + v.push_back(columns[20] + " = " + std::to_string(e.size)); + v.push_back(columns[21] + " = " + std::to_string(e.solid_type)); + v.push_back(columns[22] + " = " + std::to_string(e.incline)); v.push_back(columns[23] + " = " + std::to_string(e.tilt_x)); v.push_back(columns[24] + " = " + std::to_string(e.tilt_y)); v.push_back(columns[25] + " = '" + Strings::Escape(e.display_name) + "'"); @@ -358,8 +357,6 @@ public: v.push_back(std::to_string(e.type)); v.push_back(std::to_string(e.icon)); v.push_back(std::to_string(e.size_percentage)); - v.push_back(std::to_string(e.solid_type)); - v.push_back(std::to_string(e.incline)); v.push_back(std::to_string(e.unknown24)); v.push_back(std::to_string(e.unknown60)); v.push_back(std::to_string(e.unknown64)); @@ -368,6 +365,8 @@ public: v.push_back(std::to_string(e.unknown76)); v.push_back(std::to_string(e.unknown84)); v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.solid_type)); + v.push_back(std::to_string(e.incline)); v.push_back(std::to_string(e.tilt_x)); v.push_back(std::to_string(e.tilt_y)); v.push_back("'" + Strings::Escape(e.display_name) + "'"); @@ -417,8 +416,6 @@ public: v.push_back(std::to_string(e.type)); v.push_back(std::to_string(e.icon)); v.push_back(std::to_string(e.size_percentage)); - v.push_back(std::to_string(e.solid_type)); - v.push_back(std::to_string(e.incline)); v.push_back(std::to_string(e.unknown24)); v.push_back(std::to_string(e.unknown60)); v.push_back(std::to_string(e.unknown64)); @@ -427,6 +424,8 @@ public: v.push_back(std::to_string(e.unknown76)); v.push_back(std::to_string(e.unknown84)); v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.solid_type)); + v.push_back(std::to_string(e.incline)); v.push_back(std::to_string(e.tilt_x)); v.push_back(std::to_string(e.tilt_y)); v.push_back("'" + Strings::Escape(e.display_name) + "'"); @@ -468,30 +467,30 @@ public: Object e{}; e.id = static_cast(atoi(row[0])); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.xpos = strtof(row[3], nullptr); - e.ypos = strtof(row[4], nullptr); - e.zpos = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.xpos = row[3] ? strtof(row[3], nullptr) : 0; + e.ypos = row[4] ? strtof(row[4], nullptr) : 0; + e.zpos = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.itemid = static_cast(atoi(row[7])); - e.charges = static_cast(strtoul(row[8], nullptr, 10)); + e.charges = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.objectname = row[9] ? row[9] : ""; e.type = static_cast(atoi(row[10])); e.icon = static_cast(atoi(row[11])); - e.size_percentage = strtof(row[12], nullptr); - e.solid_type = static_cast(atoi(row[13])); - e.incline = static_cast(atoi(row[14])); - e.unknown24 = static_cast(atoi(row[15])); - e.unknown60 = static_cast(atoi(row[16])); - e.unknown64 = static_cast(atoi(row[17])); - e.unknown68 = static_cast(atoi(row[18])); - e.unknown72 = static_cast(atoi(row[19])); - e.unknown76 = static_cast(atoi(row[20])); - e.unknown84 = static_cast(atoi(row[21])); - e.size = strtof(row[22], nullptr); - e.tilt_x = strtof(row[23], nullptr); - e.tilt_y = strtof(row[24], nullptr); + e.size_percentage = row[12] ? strtof(row[12], nullptr) : 0; + e.unknown24 = static_cast(atoi(row[13])); + e.unknown60 = static_cast(atoi(row[14])); + e.unknown64 = static_cast(atoi(row[15])); + e.unknown68 = static_cast(atoi(row[16])); + e.unknown72 = static_cast(atoi(row[17])); + e.unknown76 = static_cast(atoi(row[18])); + e.unknown84 = static_cast(atoi(row[19])); + e.size = row[20] ? strtof(row[20], nullptr) : 100; + e.solid_type = static_cast(atoi(row[21])); + e.incline = static_cast(atoi(row[22])); + e.tilt_x = row[23] ? strtof(row[23], nullptr) : 0; + e.tilt_y = row[24] ? strtof(row[24], nullptr) : 0; e.display_name = row[25] ? row[25] : ""; e.min_expansion = static_cast(atoi(row[26])); e.max_expansion = static_cast(atoi(row[27])); @@ -522,30 +521,30 @@ public: Object e{}; e.id = static_cast(atoi(row[0])); - e.zoneid = static_cast(strtoul(row[1], nullptr, 10)); + e.zoneid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.version = static_cast(atoi(row[2])); - e.xpos = strtof(row[3], nullptr); - e.ypos = strtof(row[4], nullptr); - e.zpos = strtof(row[5], nullptr); - e.heading = strtof(row[6], nullptr); + e.xpos = row[3] ? strtof(row[3], nullptr) : 0; + e.ypos = row[4] ? strtof(row[4], nullptr) : 0; + e.zpos = row[5] ? strtof(row[5], nullptr) : 0; + e.heading = row[6] ? strtof(row[6], nullptr) : 0; e.itemid = static_cast(atoi(row[7])); - e.charges = static_cast(strtoul(row[8], nullptr, 10)); + e.charges = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.objectname = row[9] ? row[9] : ""; e.type = static_cast(atoi(row[10])); e.icon = static_cast(atoi(row[11])); - e.size_percentage = strtof(row[12], nullptr); - e.solid_type = static_cast(atoi(row[13])); - e.incline = static_cast(atoi(row[14])); - e.unknown24 = static_cast(atoi(row[15])); - e.unknown60 = static_cast(atoi(row[16])); - e.unknown64 = static_cast(atoi(row[17])); - e.unknown68 = static_cast(atoi(row[18])); - e.unknown72 = static_cast(atoi(row[19])); - e.unknown76 = static_cast(atoi(row[20])); - e.unknown84 = static_cast(atoi(row[21])); - e.size = strtof(row[22], nullptr); - e.tilt_x = strtof(row[23], nullptr); - e.tilt_y = strtof(row[24], nullptr); + e.size_percentage = row[12] ? strtof(row[12], nullptr) : 0; + e.unknown24 = static_cast(atoi(row[13])); + e.unknown60 = static_cast(atoi(row[14])); + e.unknown64 = static_cast(atoi(row[15])); + e.unknown68 = static_cast(atoi(row[16])); + e.unknown72 = static_cast(atoi(row[17])); + e.unknown76 = static_cast(atoi(row[18])); + e.unknown84 = static_cast(atoi(row[19])); + e.size = row[20] ? strtof(row[20], nullptr) : 100; + e.solid_type = static_cast(atoi(row[21])); + e.incline = static_cast(atoi(row[22])); + e.tilt_x = row[23] ? strtof(row[23], nullptr) : 0; + e.tilt_y = row[24] ? strtof(row[24], nullptr) : 0; e.display_name = row[25] ? row[25] : ""; e.min_expansion = static_cast(atoi(row[26])); e.max_expansion = static_cast(atoi(row[27])); @@ -609,6 +608,120 @@ 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 Object &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.xpos)); + v.push_back(std::to_string(e.ypos)); + v.push_back(std::to_string(e.zpos)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back("'" + Strings::Escape(e.objectname) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.size_percentage)); + v.push_back(std::to_string(e.unknown24)); + v.push_back(std::to_string(e.unknown60)); + v.push_back(std::to_string(e.unknown64)); + v.push_back(std::to_string(e.unknown68)); + v.push_back(std::to_string(e.unknown72)); + v.push_back(std::to_string(e.unknown76)); + v.push_back(std::to_string(e.unknown84)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.solid_type)); + v.push_back(std::to_string(e.incline)); + v.push_back(std::to_string(e.tilt_x)); + v.push_back(std::to_string(e.tilt_y)); + v.push_back("'" + Strings::Escape(e.display_name) + "'"); + 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) + "'"); + + 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(std::to_string(e.zoneid)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.xpos)); + v.push_back(std::to_string(e.ypos)); + v.push_back(std::to_string(e.zpos)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.itemid)); + v.push_back(std::to_string(e.charges)); + v.push_back("'" + Strings::Escape(e.objectname) + "'"); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.size_percentage)); + v.push_back(std::to_string(e.unknown24)); + v.push_back(std::to_string(e.unknown60)); + v.push_back(std::to_string(e.unknown64)); + v.push_back(std::to_string(e.unknown68)); + v.push_back(std::to_string(e.unknown72)); + v.push_back(std::to_string(e.unknown76)); + v.push_back(std::to_string(e.unknown84)); + v.push_back(std::to_string(e.size)); + v.push_back(std::to_string(e.solid_type)); + v.push_back(std::to_string(e.incline)); + v.push_back(std::to_string(e.tilt_x)); + v.push_back(std::to_string(e.tilt_y)); + v.push_back("'" + Strings::Escape(e.display_name) + "'"); + 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) + "'"); + + 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_OBJECT_REPOSITORY_H diff --git a/common/repositories/base/base_perl_event_export_settings_repository.h b/common/repositories/base/base_perl_event_export_settings_repository.h index d4e2fcafc..69baa52fb 100644 --- a/common/repositories/base/base_perl_event_export_settings_repository.h +++ b/common/repositories/base/base_perl_event_export_settings_repository.h @@ -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_PERL_EVENT_EXPORT_SETTINGS_REPOSITORY_H @@ -128,8 +128,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), perl_event_export_settings_id ) ); @@ -378,6 +379,74 @@ 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 PerlEventExportSettings &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.event_id)); + v.push_back("'" + Strings::Escape(e.event_description) + "'"); + v.push_back(std::to_string(e.export_qglobals)); + v.push_back(std::to_string(e.export_mob)); + v.push_back(std::to_string(e.export_zone)); + v.push_back(std::to_string(e.export_item)); + v.push_back(std::to_string(e.export_event)); + + 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.event_id)); + v.push_back("'" + Strings::Escape(e.event_description) + "'"); + v.push_back(std::to_string(e.export_qglobals)); + v.push_back(std::to_string(e.export_mob)); + v.push_back(std::to_string(e.export_zone)); + v.push_back(std::to_string(e.export_item)); + v.push_back(std::to_string(e.export_event)); + + 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_PERL_EVENT_EXPORT_SETTINGS_REPOSITORY_H diff --git a/common/repositories/base/base_petitions_repository.h b/common/repositories/base/base_petitions_repository.h index 94706c16c..dd4fd9b16 100644 --- a/common/repositories/base/base_petitions_repository.h +++ b/common/repositories/base/base_petitions_repository.h @@ -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_PETITIONS_REPOSITORY_H @@ -164,8 +164,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), petitions_id ) ); @@ -174,8 +175,8 @@ public: if (results.RowCount() == 1) { Petitions e{}; - e.dib = static_cast(strtoul(row[0], nullptr, 10)); - e.petid = static_cast(strtoul(row[1], nullptr, 10)); + e.dib = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.petid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.accountname = row[3] ? row[3] : ""; e.lastgm = row[4] ? row[4] : ""; @@ -189,7 +190,7 @@ public: e.checkouts = static_cast(atoi(row[12])); e.unavailables = static_cast(atoi(row[13])); e.ischeckedout = static_cast(atoi(row[14])); - e.senttime = strtoll(row[15], nullptr, 10); + e.senttime = row[15] ? strtoll(row[15], nullptr, 10) : 0; return e; } @@ -353,8 +354,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Petitions e{}; - e.dib = static_cast(strtoul(row[0], nullptr, 10)); - e.petid = static_cast(strtoul(row[1], nullptr, 10)); + e.dib = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.petid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.accountname = row[3] ? row[3] : ""; e.lastgm = row[4] ? row[4] : ""; @@ -368,7 +369,7 @@ public: e.checkouts = static_cast(atoi(row[12])); e.unavailables = static_cast(atoi(row[13])); e.ischeckedout = static_cast(atoi(row[14])); - e.senttime = strtoll(row[15], nullptr, 10); + e.senttime = row[15] ? strtoll(row[15], nullptr, 10) : 0; all_entries.push_back(e); } @@ -393,8 +394,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Petitions e{}; - e.dib = static_cast(strtoul(row[0], nullptr, 10)); - e.petid = static_cast(strtoul(row[1], nullptr, 10)); + e.dib = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.petid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.charname = row[2] ? row[2] : ""; e.accountname = row[3] ? row[3] : ""; e.lastgm = row[4] ? row[4] : ""; @@ -408,7 +409,7 @@ public: e.checkouts = static_cast(atoi(row[12])); e.unavailables = static_cast(atoi(row[13])); e.ischeckedout = static_cast(atoi(row[14])); - e.senttime = strtoll(row[15], nullptr, 10); + e.senttime = row[15] ? strtoll(row[15], nullptr, 10) : 0; all_entries.push_back(e); } @@ -467,6 +468,92 @@ 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 Petitions &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.dib)); + v.push_back(std::to_string(e.petid)); + v.push_back("'" + Strings::Escape(e.charname) + "'"); + v.push_back("'" + Strings::Escape(e.accountname) + "'"); + v.push_back("'" + Strings::Escape(e.lastgm) + "'"); + v.push_back("'" + Strings::Escape(e.petitiontext) + "'"); + v.push_back("'" + Strings::Escape(e.gmtext) + "'"); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.urgency)); + v.push_back(std::to_string(e.charclass)); + v.push_back(std::to_string(e.charrace)); + v.push_back(std::to_string(e.charlevel)); + v.push_back(std::to_string(e.checkouts)); + v.push_back(std::to_string(e.unavailables)); + v.push_back(std::to_string(e.ischeckedout)); + v.push_back(std::to_string(e.senttime)); + + 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.dib)); + v.push_back(std::to_string(e.petid)); + v.push_back("'" + Strings::Escape(e.charname) + "'"); + v.push_back("'" + Strings::Escape(e.accountname) + "'"); + v.push_back("'" + Strings::Escape(e.lastgm) + "'"); + v.push_back("'" + Strings::Escape(e.petitiontext) + "'"); + v.push_back("'" + Strings::Escape(e.gmtext) + "'"); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.urgency)); + v.push_back(std::to_string(e.charclass)); + v.push_back(std::to_string(e.charrace)); + v.push_back(std::to_string(e.charlevel)); + v.push_back(std::to_string(e.checkouts)); + v.push_back(std::to_string(e.unavailables)); + v.push_back(std::to_string(e.ischeckedout)); + v.push_back(std::to_string(e.senttime)); + + 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_PETITIONS_REPOSITORY_H diff --git a/common/repositories/base/base_pets_beastlord_data_repository.h b/common/repositories/base/base_pets_beastlord_data_repository.h index fd0519f6e..6cc168af8 100644 --- a/common/repositories/base/base_pets_beastlord_data_repository.h +++ b/common/repositories/base/base_pets_beastlord_data_repository.h @@ -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_PETS_BEASTLORD_DATA_REPOSITORY_H @@ -128,8 +128,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), pets_beastlord_data_id ) ); @@ -138,12 +139,12 @@ public: if (results.RowCount() == 1) { PetsBeastlordData e{}; - e.player_race = static_cast(strtoul(row[0], nullptr, 10)); - e.pet_race = static_cast(strtoul(row[1], nullptr, 10)); - e.texture = static_cast(strtoul(row[2], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[3], nullptr, 10)); - e.gender = static_cast(strtoul(row[4], nullptr, 10)); - e.face = static_cast(strtoul(row[6], nullptr, 10)); + e.player_race = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 1; + e.pet_race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 42; + e.texture = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.helm_texture = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.gender = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 2; + e.face = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; return e; } @@ -281,12 +282,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PetsBeastlordData e{}; - e.player_race = static_cast(strtoul(row[0], nullptr, 10)); - e.pet_race = static_cast(strtoul(row[1], nullptr, 10)); - e.texture = static_cast(strtoul(row[2], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[3], nullptr, 10)); - e.gender = static_cast(strtoul(row[4], nullptr, 10)); - e.face = static_cast(strtoul(row[6], nullptr, 10)); + e.player_race = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 1; + e.pet_race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 42; + e.texture = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.helm_texture = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.gender = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 2; + e.face = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -311,12 +312,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PetsBeastlordData e{}; - e.player_race = static_cast(strtoul(row[0], nullptr, 10)); - e.pet_race = static_cast(strtoul(row[1], nullptr, 10)); - e.texture = static_cast(strtoul(row[2], nullptr, 10)); - e.helm_texture = static_cast(strtoul(row[3], nullptr, 10)); - e.gender = static_cast(strtoul(row[4], nullptr, 10)); - e.face = static_cast(strtoul(row[6], nullptr, 10)); + e.player_race = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 1; + e.pet_race = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 42; + e.texture = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.helm_texture = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.gender = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 2; + e.face = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -375,6 +376,74 @@ 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 PetsBeastlordData &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.player_race)); + v.push_back(std::to_string(e.pet_race)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helm_texture)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.size_modifier)); + v.push_back(std::to_string(e.face)); + + 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.player_race)); + v.push_back(std::to_string(e.pet_race)); + v.push_back(std::to_string(e.texture)); + v.push_back(std::to_string(e.helm_texture)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.size_modifier)); + v.push_back(std::to_string(e.face)); + + 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_PETS_BEASTLORD_DATA_REPOSITORY_H diff --git a/common/repositories/base/base_pets_equipmentset_entries_repository.h b/common/repositories/base/base_pets_equipmentset_entries_repository.h index c6ba9b48a..7f650a175 100644 --- a/common/repositories/base/base_pets_equipmentset_entries_repository.h +++ b/common/repositories/base/base_pets_equipmentset_entries_repository.h @@ -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_PETS_EQUIPMENTSET_ENTRIES_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), pets_equipmentset_entries_id ) ); @@ -338,6 +339,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 PetsEquipmentsetEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.set_id)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.item_id)); + + 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.set_id)); + v.push_back(std::to_string(e.slot)); + v.push_back(std::to_string(e.item_id)); + + 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_PETS_EQUIPMENTSET_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_pets_equipmentset_repository.h b/common/repositories/base/base_pets_equipmentset_repository.h index 944df956f..04fe06df3 100644 --- a/common/repositories/base/base_pets_equipmentset_repository.h +++ b/common/repositories/base/base_pets_equipmentset_repository.h @@ -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_PETS_EQUIPMENTSET_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), pets_equipmentset_id ) ); @@ -338,6 +339,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 PetsEquipmentset &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.set_id)); + v.push_back("'" + Strings::Escape(e.setname) + "'"); + v.push_back(std::to_string(e.nested_set)); + + 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.set_id)); + v.push_back("'" + Strings::Escape(e.setname) + "'"); + v.push_back(std::to_string(e.nested_set)); + + 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_PETS_EQUIPMENTSET_REPOSITORY_H diff --git a/common/repositories/base/base_pets_repository.h b/common/repositories/base/base_pets_repository.h index dff44229f..e1dcf101e 100644 --- a/common/repositories/base/base_pets_repository.h +++ b/common/repositories/base/base_pets_repository.h @@ -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_PETS_REPOSITORY_H @@ -136,8 +136,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), pets_id ) ); @@ -397,6 +398,78 @@ 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 Pets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.type) + "'"); + v.push_back(std::to_string(e.petpower)); + v.push_back(std::to_string(e.npcID)); + v.push_back(std::to_string(e.temp)); + v.push_back(std::to_string(e.petcontrol)); + v.push_back(std::to_string(e.petnaming)); + v.push_back(std::to_string(e.monsterflag)); + v.push_back(std::to_string(e.equipmentset)); + + 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.type) + "'"); + v.push_back(std::to_string(e.petpower)); + v.push_back(std::to_string(e.npcID)); + v.push_back(std::to_string(e.temp)); + v.push_back(std::to_string(e.petcontrol)); + v.push_back(std::to_string(e.petnaming)); + v.push_back(std::to_string(e.monsterflag)); + v.push_back(std::to_string(e.equipmentset)); + + 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_PETS_REPOSITORY_H diff --git a/common/repositories/base/base_player_event_log_settings_repository.h b/common/repositories/base/base_player_event_log_settings_repository.h index ad359c2b0..d8122b66e 100644 --- a/common/repositories/base/base_player_event_log_settings_repository.h +++ b/common/repositories/base/base_player_event_log_settings_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BasePlayerEventLogSettingsRepository { public: struct PlayerEventLogSettings { @@ -132,7 +131,7 @@ public: if (results.RowCount() == 1) { PlayerEventLogSettings e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.event_name = row[1] ? row[1] : ""; e.event_enabled = static_cast(atoi(row[2])); e.retention_days = static_cast(atoi(row[3])); @@ -268,7 +267,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerEventLogSettings e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.event_name = row[1] ? row[1] : ""; e.event_enabled = static_cast(atoi(row[2])); e.retention_days = static_cast(atoi(row[3])); @@ -297,7 +296,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerEventLogSettings e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.event_name = row[1] ? row[1] : ""; e.event_enabled = static_cast(atoi(row[2])); e.retention_days = static_cast(atoi(row[3])); diff --git a/common/repositories/base/base_player_event_logs_repository.h b/common/repositories/base/base_player_event_logs_repository.h index 4e188dc16..1c14dca82 100644 --- a/common/repositories/base/base_player_event_logs_repository.h +++ b/common/repositories/base/base_player_event_logs_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include #include - class BasePlayerEventLogsRepository { public: struct PlayerEventLogs { @@ -185,15 +184,15 @@ public: if (results.RowCount() == 1) { PlayerEventLogs e{}; - e.id = strtoll(row[0], nullptr, 10); - e.account_id = strtoll(row[1], nullptr, 10); - e.character_id = strtoll(row[2], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.account_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; + e.character_id = row[2] ? strtoll(row[2], nullptr, 10) : 0; e.zone_id = static_cast(atoi(row[3])); e.instance_id = static_cast(atoi(row[4])); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.event_type_id = static_cast(atoi(row[9])); e.event_type_name = row[10] ? row[10] : ""; e.event_data = row[11] ? row[11] : ""; @@ -352,15 +351,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerEventLogs e{}; - e.id = strtoll(row[0], nullptr, 10); - e.account_id = strtoll(row[1], nullptr, 10); - e.character_id = strtoll(row[2], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.account_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; + e.character_id = row[2] ? strtoll(row[2], nullptr, 10) : 0; e.zone_id = static_cast(atoi(row[3])); e.instance_id = static_cast(atoi(row[4])); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.event_type_id = static_cast(atoi(row[9])); e.event_type_name = row[10] ? row[10] : ""; e.event_data = row[11] ? row[11] : ""; @@ -389,15 +388,15 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerEventLogs e{}; - e.id = strtoll(row[0], nullptr, 10); - e.account_id = strtoll(row[1], nullptr, 10); - e.character_id = strtoll(row[2], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.account_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; + e.character_id = row[2] ? strtoll(row[2], nullptr, 10) : 0; e.zone_id = static_cast(atoi(row[3])); e.instance_id = static_cast(atoi(row[4])); - e.x = strtof(row[5], nullptr); - e.y = strtof(row[6], nullptr); - e.z = strtof(row[7], nullptr); - e.heading = strtof(row[8], nullptr); + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.y = row[6] ? strtof(row[6], nullptr) : 0; + e.z = row[7] ? strtof(row[7], nullptr) : 0; + e.heading = row[8] ? strtof(row[8], nullptr) : 0; e.event_type_id = static_cast(atoi(row[9])); e.event_type_name = row[10] ? row[10] : ""; e.event_data = row[11] ? row[11] : ""; diff --git a/common/repositories/base/base_player_titlesets_repository.h b/common/repositories/base/base_player_titlesets_repository.h index 2904ce0fb..094411d48 100644 --- a/common/repositories/base/base_player_titlesets_repository.h +++ b/common/repositories/base/base_player_titlesets_repository.h @@ -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_PLAYER_TITLESETS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), player_titlesets_id ) ); @@ -122,9 +123,9 @@ public: if (results.RowCount() == 1) { PlayerTitlesets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.char_id = static_cast(strtoul(row[1], nullptr, 10)); - e.title_set = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.char_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title_set = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; return e; } @@ -249,9 +250,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerTitlesets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.char_id = static_cast(strtoul(row[1], nullptr, 10)); - e.title_set = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.char_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title_set = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -276,9 +277,9 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { PlayerTitlesets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.char_id = static_cast(strtoul(row[1], nullptr, 10)); - e.title_set = static_cast(strtoul(row[2], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.char_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.title_set = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -337,6 +338,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 PlayerTitlesets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.title_set)); + + 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(std::to_string(e.char_id)); + v.push_back(std::to_string(e.title_set)); + + 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_PLAYER_TITLESETS_REPOSITORY_H diff --git a/common/repositories/base/base_quest_globals_repository.h b/common/repositories/base/base_quest_globals_repository.h index c09e955a7..d2ad8fc95 100644 --- a/common/repositories/base/base_quest_globals_repository.h +++ b/common/repositories/base/base_quest_globals_repository.h @@ -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_QUEST_GLOBALS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), quest_globals_id ) ); @@ -368,6 +369,72 @@ 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 QuestGlobals &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.npcid)); + v.push_back(std::to_string(e.zoneid)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back(std::to_string(e.expdate)); + + 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.charid)); + v.push_back(std::to_string(e.npcid)); + v.push_back(std::to_string(e.zoneid)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back(std::to_string(e.expdate)); + + 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_QUEST_GLOBALS_REPOSITORY_H diff --git a/common/repositories/base/base_raid_details_repository.h b/common/repositories/base/base_raid_details_repository.h index 616490dd5..704fbbb8b 100644 --- a/common/repositories/base/base_raid_details_repository.h +++ b/common/repositories/base/base_raid_details_repository.h @@ -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_RAID_DETAILS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseRaidDetailsRepository { public: struct RaidDetails { @@ -168,15 +167,15 @@ public: e.loottype = static_cast(atoi(row[1])); e.locked = static_cast(atoi(row[2])); e.motd = row[3] ? row[3] : ""; - e.marked_npc_1_entity_id = static_cast(strtoul(row[4], nullptr, 10)); - e.marked_npc_1_zone_id = static_cast(strtoul(row[5], nullptr, 10)); - e.marked_npc_1_instance_id = static_cast(strtoul(row[6], nullptr, 10)); - e.marked_npc_2_entity_id = static_cast(strtoul(row[7], nullptr, 10)); - e.marked_npc_2_zone_id = static_cast(strtoul(row[8], nullptr, 10)); - e.marked_npc_2_instance_id = static_cast(strtoul(row[9], nullptr, 10)); - e.marked_npc_3_entity_id = static_cast(strtoul(row[10], nullptr, 10)); - e.marked_npc_3_zone_id = static_cast(strtoul(row[11], nullptr, 10)); - e.marked_npc_3_instance_id = static_cast(strtoul(row[12], nullptr, 10)); + e.marked_npc_1_entity_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.marked_npc_1_zone_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.marked_npc_1_instance_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.marked_npc_2_entity_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.marked_npc_2_zone_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.marked_npc_2_instance_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.marked_npc_3_entity_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.marked_npc_3_zone_id = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.marked_npc_3_instance_id = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; return e; } @@ -336,15 +335,15 @@ public: e.loottype = static_cast(atoi(row[1])); e.locked = static_cast(atoi(row[2])); e.motd = row[3] ? row[3] : ""; - e.marked_npc_1_entity_id = static_cast(strtoul(row[4], nullptr, 10)); - e.marked_npc_1_zone_id = static_cast(strtoul(row[5], nullptr, 10)); - e.marked_npc_1_instance_id = static_cast(strtoul(row[6], nullptr, 10)); - e.marked_npc_2_entity_id = static_cast(strtoul(row[7], nullptr, 10)); - e.marked_npc_2_zone_id = static_cast(strtoul(row[8], nullptr, 10)); - e.marked_npc_2_instance_id = static_cast(strtoul(row[9], nullptr, 10)); - e.marked_npc_3_entity_id = static_cast(strtoul(row[10], nullptr, 10)); - e.marked_npc_3_zone_id = static_cast(strtoul(row[11], nullptr, 10)); - e.marked_npc_3_instance_id = static_cast(strtoul(row[12], nullptr, 10)); + e.marked_npc_1_entity_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.marked_npc_1_zone_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.marked_npc_1_instance_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.marked_npc_2_entity_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.marked_npc_2_zone_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.marked_npc_2_instance_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.marked_npc_3_entity_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.marked_npc_3_zone_id = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.marked_npc_3_instance_id = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -373,15 +372,15 @@ public: e.loottype = static_cast(atoi(row[1])); e.locked = static_cast(atoi(row[2])); e.motd = row[3] ? row[3] : ""; - e.marked_npc_1_entity_id = static_cast(strtoul(row[4], nullptr, 10)); - e.marked_npc_1_zone_id = static_cast(strtoul(row[5], nullptr, 10)); - e.marked_npc_1_instance_id = static_cast(strtoul(row[6], nullptr, 10)); - e.marked_npc_2_entity_id = static_cast(strtoul(row[7], nullptr, 10)); - e.marked_npc_2_zone_id = static_cast(strtoul(row[8], nullptr, 10)); - e.marked_npc_2_instance_id = static_cast(strtoul(row[9], nullptr, 10)); - e.marked_npc_3_entity_id = static_cast(strtoul(row[10], nullptr, 10)); - e.marked_npc_3_zone_id = static_cast(strtoul(row[11], nullptr, 10)); - e.marked_npc_3_instance_id = static_cast(strtoul(row[12], nullptr, 10)); + e.marked_npc_1_entity_id = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.marked_npc_1_zone_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.marked_npc_1_instance_id = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.marked_npc_2_entity_id = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.marked_npc_2_zone_id = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.marked_npc_2_instance_id = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; + e.marked_npc_3_entity_id = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.marked_npc_3_zone_id = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.marked_npc_3_instance_id = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -440,6 +439,86 @@ 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 RaidDetails &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.raidid)); + v.push_back(std::to_string(e.loottype)); + v.push_back(std::to_string(e.locked)); + v.push_back("'" + Strings::Escape(e.motd) + "'"); + v.push_back(std::to_string(e.marked_npc_1_entity_id)); + v.push_back(std::to_string(e.marked_npc_1_zone_id)); + v.push_back(std::to_string(e.marked_npc_1_instance_id)); + v.push_back(std::to_string(e.marked_npc_2_entity_id)); + v.push_back(std::to_string(e.marked_npc_2_zone_id)); + v.push_back(std::to_string(e.marked_npc_2_instance_id)); + v.push_back(std::to_string(e.marked_npc_3_entity_id)); + v.push_back(std::to_string(e.marked_npc_3_zone_id)); + v.push_back(std::to_string(e.marked_npc_3_instance_id)); + + 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.raidid)); + v.push_back(std::to_string(e.loottype)); + v.push_back(std::to_string(e.locked)); + v.push_back("'" + Strings::Escape(e.motd) + "'"); + v.push_back(std::to_string(e.marked_npc_1_entity_id)); + v.push_back(std::to_string(e.marked_npc_1_zone_id)); + v.push_back(std::to_string(e.marked_npc_1_instance_id)); + v.push_back(std::to_string(e.marked_npc_2_entity_id)); + v.push_back(std::to_string(e.marked_npc_2_zone_id)); + v.push_back(std::to_string(e.marked_npc_2_instance_id)); + v.push_back(std::to_string(e.marked_npc_3_entity_id)); + v.push_back(std::to_string(e.marked_npc_3_zone_id)); + v.push_back(std::to_string(e.marked_npc_3_instance_id)); + + 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_RAID_DETAILS_REPOSITORY_H diff --git a/common/repositories/base/base_raid_members_repository.h b/common/repositories/base/base_raid_members_repository.h index 295325a9d..582a4eb9e 100644 --- a/common/repositories/base/base_raid_members_repository.h +++ b/common/repositories/base/base_raid_members_repository.h @@ -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_RAID_MEMBERS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseRaidMembersRepository { public: struct RaidMembers { @@ -168,19 +167,19 @@ public: if (results.RowCount() == 1) { RaidMembers e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.raidid = static_cast(atoi(row[1])); e.charid = static_cast(atoi(row[2])); e.bot_id = static_cast(atoi(row[3])); - e.groupid = static_cast(strtoul(row[4], nullptr, 10)); + e.groupid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e._class = static_cast(atoi(row[5])); e.level = static_cast(atoi(row[6])); e.name = row[7] ? row[7] : ""; e.isgroupleader = static_cast(atoi(row[8])); e.israidleader = static_cast(atoi(row[9])); e.islooter = static_cast(atoi(row[10])); - e.is_marker = static_cast(strtoul(row[11], nullptr, 10)); - e.is_assister = static_cast(strtoul(row[12], nullptr, 10)); + e.is_marker = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.is_assister = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.note = row[13] ? row[13] : ""; return e; @@ -339,19 +338,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RaidMembers e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.raidid = static_cast(atoi(row[1])); e.charid = static_cast(atoi(row[2])); e.bot_id = static_cast(atoi(row[3])); - e.groupid = static_cast(strtoul(row[4], nullptr, 10)); + e.groupid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e._class = static_cast(atoi(row[5])); e.level = static_cast(atoi(row[6])); e.name = row[7] ? row[7] : ""; e.isgroupleader = static_cast(atoi(row[8])); e.israidleader = static_cast(atoi(row[9])); e.islooter = static_cast(atoi(row[10])); - e.is_marker = static_cast(strtoul(row[11], nullptr, 10)); - e.is_assister = static_cast(strtoul(row[12], nullptr, 10)); + e.is_marker = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.is_assister = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.note = row[13] ? row[13] : ""; all_entries.push_back(e); @@ -377,19 +376,19 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RaidMembers e{}; - e.id = strtoull(row[0], nullptr, 10); + e.id = row[0] ? strtoull(row[0], nullptr, 10) : 0; e.raidid = static_cast(atoi(row[1])); e.charid = static_cast(atoi(row[2])); e.bot_id = static_cast(atoi(row[3])); - e.groupid = static_cast(strtoul(row[4], nullptr, 10)); + e.groupid = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e._class = static_cast(atoi(row[5])); e.level = static_cast(atoi(row[6])); e.name = row[7] ? row[7] : ""; e.isgroupleader = static_cast(atoi(row[8])); e.israidleader = static_cast(atoi(row[9])); e.islooter = static_cast(atoi(row[10])); - e.is_marker = static_cast(strtoul(row[11], nullptr, 10)); - e.is_assister = static_cast(strtoul(row[12], nullptr, 10)); + e.is_marker = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; + e.is_assister = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.note = row[13] ? row[13] : ""; all_entries.push_back(e); @@ -449,6 +448,88 @@ 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 RaidMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.raidid)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.groupid)); + v.push_back(std::to_string(e._class)); + v.push_back(std::to_string(e.level)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.isgroupleader)); + v.push_back(std::to_string(e.israidleader)); + v.push_back(std::to_string(e.islooter)); + v.push_back(std::to_string(e.is_marker)); + v.push_back(std::to_string(e.is_assister)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + + 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(std::to_string(e.raidid)); + v.push_back(std::to_string(e.charid)); + v.push_back(std::to_string(e.bot_id)); + v.push_back(std::to_string(e.groupid)); + v.push_back(std::to_string(e._class)); + v.push_back(std::to_string(e.level)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.isgroupleader)); + v.push_back(std::to_string(e.israidleader)); + v.push_back(std::to_string(e.islooter)); + v.push_back(std::to_string(e.is_marker)); + v.push_back(std::to_string(e.is_assister)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + + 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_RAID_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_reports_repository.h b/common/repositories/base/base_reports_repository.h index 3a45fe730..1a3eac65b 100644 --- a/common/repositories/base/base_reports_repository.h +++ b/common/repositories/base/base_reports_repository.h @@ -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_REPORTS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), reports_id ) ); @@ -126,7 +127,7 @@ public: if (results.RowCount() == 1) { Reports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.reported = row[2] ? row[2] : ""; e.reported_text = row[3] ? row[3] : ""; @@ -257,7 +258,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Reports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.reported = row[2] ? row[2] : ""; e.reported_text = row[3] ? row[3] : ""; @@ -285,7 +286,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Reports e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; e.reported = row[2] ? row[2] : ""; e.reported_text = row[3] ? row[3] : ""; @@ -347,6 +348,68 @@ 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 Reports &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.reported) + "'"); + v.push_back("'" + Strings::Escape(e.reported_text) + "'"); + + 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.name) + "'"); + v.push_back("'" + Strings::Escape(e.reported) + "'"); + v.push_back("'" + Strings::Escape(e.reported_text) + "'"); + + 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_REPORTS_REPOSITORY_H diff --git a/common/repositories/base/base_respawn_times_repository.h b/common/repositories/base/base_respawn_times_repository.h index 446a78216..6e8f4206a 100644 --- a/common/repositories/base/base_respawn_times_repository.h +++ b/common/repositories/base/base_respawn_times_repository.h @@ -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_RESPAWN_TIMES_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), respawn_times_id ) ); @@ -348,6 +349,68 @@ 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 RespawnTimes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.start)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.instance_id)); + + 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(std::to_string(e.start)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.instance_id)); + + 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_RESPAWN_TIMES_REPOSITORY_H diff --git a/common/repositories/base/base_rule_sets_repository.h b/common/repositories/base/base_rule_sets_repository.h index 461c6f1e6..e4f51f69d 100644 --- a/common/repositories/base/base_rule_sets_repository.h +++ b/common/repositories/base/base_rule_sets_repository.h @@ -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_RULE_SETS_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), rule_sets_id ) ); @@ -118,7 +119,7 @@ public: if (results.RowCount() == 1) { RuleSets e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; return e; @@ -241,7 +242,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RuleSets e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -267,7 +268,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RuleSets e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; all_entries.push_back(e); @@ -327,6 +328,64 @@ 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 RuleSets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.ruleset_id)); + v.push_back("'" + Strings::Escape(e.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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back(std::to_string(e.ruleset_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + + 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_RULE_SETS_REPOSITORY_H diff --git a/common/repositories/base/base_rule_values_repository.h b/common/repositories/base/base_rule_values_repository.h index b98e3f7dc..6486e2b86 100644 --- a/common/repositories/base/base_rule_values_repository.h +++ b/common/repositories/base/base_rule_values_repository.h @@ -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_RULE_VALUES_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), rule_values_id ) ); @@ -126,7 +127,7 @@ public: if (results.RowCount() == 1) { RuleValues e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.rule_name = row[1] ? row[1] : ""; e.rule_value = row[2] ? row[2] : ""; e.notes = row[3] ? row[3] : ""; @@ -258,7 +259,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RuleValues e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.rule_name = row[1] ? row[1] : ""; e.rule_value = row[2] ? row[2] : ""; e.notes = row[3] ? row[3] : ""; @@ -286,7 +287,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { RuleValues e{}; - e.ruleset_id = static_cast(strtoul(row[0], nullptr, 10)); + e.ruleset_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.rule_name = row[1] ? row[1] : ""; e.rule_value = row[2] ? row[2] : ""; e.notes = row[3] ? row[3] : ""; @@ -348,6 +349,68 @@ 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 RuleValues &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.ruleset_id)); + v.push_back("'" + Strings::Escape(e.rule_name) + "'"); + v.push_back("'" + Strings::Escape(e.rule_value) + "'"); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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.ruleset_id)); + v.push_back("'" + Strings::Escape(e.rule_name) + "'"); + v.push_back("'" + Strings::Escape(e.rule_value) + "'"); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + + 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_RULE_VALUES_REPOSITORY_H diff --git a/common/repositories/base/base_saylink_repository.h b/common/repositories/base/base_saylink_repository.h index 5e35da29c..6866b36f3 100644 --- a/common/repositories/base/base_saylink_repository.h +++ b/common/repositories/base/base_saylink_repository.h @@ -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_SAYLINK_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), saylink_id ) ); @@ -327,6 +328,64 @@ 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 Saylink &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.phrase) + "'"); + + 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.phrase) + "'"); + + 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_SAYLINK_REPOSITORY_H diff --git a/common/repositories/base/base_server_scheduled_events_repository.h b/common/repositories/base/base_server_scheduled_events_repository.h index a1e32b40e..b1a7ff776 100644 --- a/common/repositories/base/base_server_scheduled_events_repository.h +++ b/common/repositories/base/base_server_scheduled_events_repository.h @@ -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_SERVER_SCHEDULED_EVENTS_REPOSITORY_H @@ -168,8 +168,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), server_scheduled_events_id ) ); @@ -477,6 +478,94 @@ 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 ServerScheduledEvents &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.description) + "'"); + v.push_back("'" + Strings::Escape(e.event_type) + "'"); + v.push_back("'" + Strings::Escape(e.event_data) + "'"); + v.push_back(std::to_string(e.minute_start)); + v.push_back(std::to_string(e.hour_start)); + v.push_back(std::to_string(e.day_start)); + v.push_back(std::to_string(e.month_start)); + v.push_back(std::to_string(e.year_start)); + v.push_back(std::to_string(e.minute_end)); + v.push_back(std::to_string(e.hour_end)); + v.push_back(std::to_string(e.day_end)); + v.push_back(std::to_string(e.month_end)); + v.push_back(std::to_string(e.year_end)); + v.push_back("'" + Strings::Escape(e.cron_expression) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.deleted_at > 0 ? std::to_string(e.deleted_at) : "null") + ")"); + + 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.description) + "'"); + v.push_back("'" + Strings::Escape(e.event_type) + "'"); + v.push_back("'" + Strings::Escape(e.event_data) + "'"); + v.push_back(std::to_string(e.minute_start)); + v.push_back(std::to_string(e.hour_start)); + v.push_back(std::to_string(e.day_start)); + v.push_back(std::to_string(e.month_start)); + v.push_back(std::to_string(e.year_start)); + v.push_back(std::to_string(e.minute_end)); + v.push_back(std::to_string(e.hour_end)); + v.push_back(std::to_string(e.day_end)); + v.push_back(std::to_string(e.month_end)); + v.push_back(std::to_string(e.year_end)); + v.push_back("'" + Strings::Escape(e.cron_expression) + "'"); + v.push_back("FROM_UNIXTIME(" + (e.created_at > 0 ? std::to_string(e.created_at) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.deleted_at > 0 ? std::to_string(e.deleted_at) : "null") + ")"); + + 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_SERVER_SCHEDULED_EVENTS_REPOSITORY_H diff --git a/common/repositories/base/base_shared_task_activity_state_repository.h b/common/repositories/base/base_shared_task_activity_state_repository.h index fb6b56531..36db2ec58 100644 --- a/common/repositories/base/base_shared_task_activity_state_repository.h +++ b/common/repositories/base/base_shared_task_activity_state_repository.h @@ -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_SHARED_TASK_ACTIVITY_STATE_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), shared_task_activity_state_id ) ); @@ -130,7 +131,7 @@ public: if (results.RowCount() == 1) { SharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -266,7 +267,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -295,7 +296,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskActivityState e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.activity_id = static_cast(atoi(row[1])); e.done_count = static_cast(atoi(row[2])); e.updated_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -358,6 +359,70 @@ 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 SharedTaskActivityState &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.shared_task_id)); + v.push_back(std::to_string(e.activity_id)); + v.push_back(std::to_string(e.done_count)); + v.push_back("FROM_UNIXTIME(" + (e.updated_time > 0 ? std::to_string(e.updated_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completed_time > 0 ? std::to_string(e.completed_time) : "null") + ")"); + + 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.shared_task_id)); + v.push_back(std::to_string(e.activity_id)); + v.push_back(std::to_string(e.done_count)); + v.push_back("FROM_UNIXTIME(" + (e.updated_time > 0 ? std::to_string(e.updated_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completed_time > 0 ? std::to_string(e.completed_time) : "null") + ")"); + + 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_SHARED_TASK_ACTIVITY_STATE_REPOSITORY_H diff --git a/common/repositories/base/base_shared_task_dynamic_zones_repository.h b/common/repositories/base/base_shared_task_dynamic_zones_repository.h index 2bf92d75a..27a40be72 100644 --- a/common/repositories/base/base_shared_task_dynamic_zones_repository.h +++ b/common/repositories/base/base_shared_task_dynamic_zones_repository.h @@ -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_SHARED_TASK_DYNAMIC_ZONES_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), shared_task_dynamic_zones_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { SharedTaskDynamicZones e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskDynamicZones e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskDynamicZones e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.dynamic_zone_id = static_cast(strtoul(row[1], nullptr, 10)); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.dynamic_zone_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 SharedTaskDynamicZones &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.shared_task_id)); + v.push_back(std::to_string(e.dynamic_zone_id)); + + 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.shared_task_id)); + v.push_back(std::to_string(e.dynamic_zone_id)); + + 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_SHARED_TASK_DYNAMIC_ZONES_REPOSITORY_H diff --git a/common/repositories/base/base_shared_task_members_repository.h b/common/repositories/base/base_shared_task_members_repository.h index b26e42c66..2da41035f 100644 --- a/common/repositories/base/base_shared_task_members_repository.h +++ b/common/repositories/base/base_shared_task_members_repository.h @@ -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_SHARED_TASK_MEMBERS_REPOSITORY_H @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), shared_task_members_id ) ); @@ -122,8 +123,8 @@ public: if (results.RowCount() == 1) { SharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); return e; @@ -250,8 +251,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -277,8 +278,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTaskMembers e{}; - e.shared_task_id = strtoll(row[0], nullptr, 10); - e.character_id = strtoll(row[1], nullptr, 10); + e.shared_task_id = row[0] ? strtoll(row[0], nullptr, 10) : 0; + e.character_id = row[1] ? strtoll(row[1], nullptr, 10) : 0; e.is_leader = static_cast(atoi(row[2])); all_entries.push_back(e); @@ -338,6 +339,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 SharedTaskMembers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.shared_task_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.is_leader)); + + 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.shared_task_id)); + v.push_back(std::to_string(e.character_id)); + v.push_back(std::to_string(e.is_leader)); + + 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_SHARED_TASK_MEMBERS_REPOSITORY_H diff --git a/common/repositories/base/base_shared_tasks_repository.h b/common/repositories/base/base_shared_tasks_repository.h index 82fee3608..8f7e320d1 100644 --- a/common/repositories/base/base_shared_tasks_repository.h +++ b/common/repositories/base/base_shared_tasks_repository.h @@ -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_SHARED_TASKS_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), shared_tasks_id ) ); @@ -134,7 +135,7 @@ public: if (results.RowCount() == 1) { SharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -273,7 +274,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -303,7 +304,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SharedTasks e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.task_id = static_cast(atoi(row[1])); e.accepted_time = strtoll(row[2] ? row[2] : "-1", nullptr, 10); e.expire_time = strtoll(row[3] ? row[3] : "-1", nullptr, 10); @@ -367,6 +368,72 @@ 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 SharedTasks &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.task_id)); + v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")"); + v.push_back(std::to_string(e.is_locked)); + + 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(std::to_string(e.task_id)); + v.push_back("FROM_UNIXTIME(" + (e.accepted_time > 0 ? std::to_string(e.accepted_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.expire_time > 0 ? std::to_string(e.expire_time) : "null") + ")"); + v.push_back("FROM_UNIXTIME(" + (e.completion_time > 0 ? std::to_string(e.completion_time) : "null") + ")"); + v.push_back(std::to_string(e.is_locked)); + + 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_SHARED_TASKS_REPOSITORY_H diff --git a/common/repositories/base/base_skill_caps_repository.h b/common/repositories/base/base_skill_caps_repository.h index c1dc1c24f..29223c2d3 100644 --- a/common/repositories/base/base_skill_caps_repository.h +++ b/common/repositories/base/base_skill_caps_repository.h @@ -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_SKILL_CAPS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), skill_caps_id ) ); @@ -130,11 +131,11 @@ public: if (results.RowCount() == 1) { SkillCaps e{}; - e.skillID = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.level = static_cast(strtoul(row[2], nullptr, 10)); - e.cap = static_cast(strtoul(row[3], nullptr, 10)); - e.class_ = static_cast(strtoul(row[4], nullptr, 10)); + e.skillID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.level = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.cap = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.class_ = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; return e; } @@ -266,11 +267,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SkillCaps e{}; - e.skillID = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.level = static_cast(strtoul(row[2], nullptr, 10)); - e.cap = static_cast(strtoul(row[3], nullptr, 10)); - e.class_ = static_cast(strtoul(row[4], nullptr, 10)); + e.skillID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.level = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.cap = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.class_ = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -295,11 +296,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SkillCaps e{}; - e.skillID = static_cast(strtoul(row[0], nullptr, 10)); - e.class_ = static_cast(strtoul(row[1], nullptr, 10)); - e.level = static_cast(strtoul(row[2], nullptr, 10)); - e.cap = static_cast(strtoul(row[3], nullptr, 10)); - e.class_ = static_cast(strtoul(row[4], nullptr, 10)); + e.skillID = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.class_ = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.level = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.cap = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.class_ = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -358,6 +359,70 @@ 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 SkillCaps &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.skillID)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.cap)); + v.push_back(std::to_string(e.class_)); + + 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.skillID)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.cap)); + v.push_back(std::to_string(e.class_)); + + 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_SKILL_CAPS_REPOSITORY_H diff --git a/common/repositories/base/base_spawn2_disabled_repository.h b/common/repositories/base/base_spawn2_disabled_repository.h index f23573a19..032066913 100644 --- a/common/repositories/base/base_spawn2_disabled_repository.h +++ b/common/repositories/base/base_spawn2_disabled_repository.h @@ -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_SPAWN2_DISABLED_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseSpawn2DisabledRepository { public: struct Spawn2Disabled { @@ -128,7 +127,7 @@ public: if (results.RowCount() == 1) { Spawn2Disabled e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.spawn2_id = static_cast(atoi(row[1])); e.instance_id = static_cast(atoi(row[2])); e.disabled = static_cast(atoi(row[3])); @@ -259,7 +258,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Spawn2Disabled e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.spawn2_id = static_cast(atoi(row[1])); e.instance_id = static_cast(atoi(row[2])); e.disabled = static_cast(atoi(row[3])); @@ -287,7 +286,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Spawn2Disabled e{}; - e.id = strtoll(row[0], nullptr, 10); + e.id = row[0] ? strtoll(row[0], nullptr, 10) : 0; e.spawn2_id = static_cast(atoi(row[1])); e.instance_id = static_cast(atoi(row[2])); e.disabled = static_cast(atoi(row[3])); @@ -349,6 +348,68 @@ 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 Spawn2Disabled &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.spawn2_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.disabled)); + + 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(std::to_string(e.spawn2_id)); + v.push_back(std::to_string(e.instance_id)); + v.push_back(std::to_string(e.disabled)); + + 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_SPAWN2_DISABLED_REPOSITORY_H diff --git a/common/repositories/base/base_spawn2_repository.h b/common/repositories/base/base_spawn2_repository.h index dd6903a26..721e72311 100644 --- a/common/repositories/base/base_spawn2_repository.h +++ b/common/repositories/base/base_spawn2_repository.h @@ -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_SPAWN2_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseSpawn2Repository { public: struct Spawn2 { @@ -192,17 +191,17 @@ public: e.spawngroupID = static_cast(atoi(row[1])); e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0.000000; + e.y = row[5] ? strtof(row[5], nullptr) : 0.000000; + e.z = row[6] ? strtof(row[6], nullptr) : 0.000000; + e.heading = row[7] ? strtof(row[7], nullptr) : 0.000000; e.respawntime = static_cast(atoi(row[8])); e.variance = static_cast(atoi(row[9])); e.pathgrid = static_cast(atoi(row[10])); e.path_when_zone_idle = static_cast(atoi(row[11])); - e._condition = static_cast(strtoul(row[12], nullptr, 10)); + e._condition = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.cond_value = static_cast(atoi(row[13])); - e.animation = static_cast(strtoul(row[14], nullptr, 10)); + e.animation = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -383,17 +382,17 @@ public: e.spawngroupID = static_cast(atoi(row[1])); e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0.000000; + e.y = row[5] ? strtof(row[5], nullptr) : 0.000000; + e.z = row[6] ? strtof(row[6], nullptr) : 0.000000; + e.heading = row[7] ? strtof(row[7], nullptr) : 0.000000; e.respawntime = static_cast(atoi(row[8])); e.variance = static_cast(atoi(row[9])); e.pathgrid = static_cast(atoi(row[10])); e.path_when_zone_idle = static_cast(atoi(row[11])); - e._condition = static_cast(strtoul(row[12], nullptr, 10)); + e._condition = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.cond_value = static_cast(atoi(row[13])); - e.animation = static_cast(strtoul(row[14], nullptr, 10)); + e.animation = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -426,17 +425,17 @@ public: e.spawngroupID = static_cast(atoi(row[1])); e.zone = row[2] ? row[2] : ""; e.version = static_cast(atoi(row[3])); - e.x = strtof(row[4], nullptr); - e.y = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); + e.x = row[4] ? strtof(row[4], nullptr) : 0.000000; + e.y = row[5] ? strtof(row[5], nullptr) : 0.000000; + e.z = row[6] ? strtof(row[6], nullptr) : 0.000000; + e.heading = row[7] ? strtof(row[7], nullptr) : 0.000000; e.respawntime = static_cast(atoi(row[8])); e.variance = static_cast(atoi(row[9])); e.pathgrid = static_cast(atoi(row[10])); e.path_when_zone_idle = static_cast(atoi(row[11])); - e._condition = static_cast(strtoul(row[12], nullptr, 10)); + e._condition = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.cond_value = static_cast(atoi(row[13])); - e.animation = static_cast(strtoul(row[14], nullptr, 10)); + e.animation = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -499,6 +498,98 @@ 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 Spawn2 &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.spawngroupID)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.respawntime)); + v.push_back(std::to_string(e.variance)); + v.push_back(std::to_string(e.pathgrid)); + v.push_back(std::to_string(e.path_when_zone_idle)); + v.push_back(std::to_string(e._condition)); + v.push_back(std::to_string(e.cond_value)); + v.push_back(std::to_string(e.animation)); + 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) + "'"); + + 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(std::to_string(e.spawngroupID)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.respawntime)); + v.push_back(std::to_string(e.variance)); + v.push_back(std::to_string(e.pathgrid)); + v.push_back(std::to_string(e.path_when_zone_idle)); + v.push_back(std::to_string(e._condition)); + v.push_back(std::to_string(e.cond_value)); + v.push_back(std::to_string(e.animation)); + 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) + "'"); + + 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_SPAWN2_REPOSITORY_H diff --git a/common/repositories/base/base_spawn_condition_values_repository.h b/common/repositories/base/base_spawn_condition_values_repository.h index 450572b0e..3464c1c01 100644 --- a/common/repositories/base/base_spawn_condition_values_repository.h +++ b/common/repositories/base/base_spawn_condition_values_repository.h @@ -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_SPAWN_CONDITION_VALUES_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spawn_condition_values_id ) ); @@ -126,10 +127,10 @@ public: if (results.RowCount() == 1) { SpawnConditionValues e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.value = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.value = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone = row[2] ? row[2] : ""; - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -258,10 +259,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpawnConditionValues e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.value = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.value = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone = row[2] ? row[2] : ""; - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -286,10 +287,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpawnConditionValues e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.value = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.value = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.zone = row[2] ? row[2] : ""; - e.instance_id = static_cast(strtoul(row[3], nullptr, 10)); + e.instance_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -348,6 +349,68 @@ 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 SpawnConditionValues &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.value)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.instance_id)); + + 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(std::to_string(e.value)); + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.instance_id)); + + 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_SPAWN_CONDITION_VALUES_REPOSITORY_H diff --git a/common/repositories/base/base_spawn_conditions_repository.h b/common/repositories/base/base_spawn_conditions_repository.h index 54d7a0ae1..96132074f 100644 --- a/common/repositories/base/base_spawn_conditions_repository.h +++ b/common/repositories/base/base_spawn_conditions_repository.h @@ -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_SPAWN_CONDITIONS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spawn_conditions_id ) ); @@ -131,9 +132,9 @@ public: SpawnConditions e{}; e.zone = row[0] ? row[0] : ""; - e.id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.value = static_cast(atoi(row[2])); - e.onchange = static_cast(strtoul(row[3], nullptr, 10)); + e.onchange = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.name = row[4] ? row[4] : ""; return e; @@ -267,9 +268,9 @@ public: SpawnConditions e{}; e.zone = row[0] ? row[0] : ""; - e.id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.value = static_cast(atoi(row[2])); - e.onchange = static_cast(strtoul(row[3], nullptr, 10)); + e.onchange = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.name = row[4] ? row[4] : ""; all_entries.push_back(e); @@ -296,9 +297,9 @@ public: SpawnConditions e{}; e.zone = row[0] ? row[0] : ""; - e.id = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 1; e.value = static_cast(atoi(row[2])); - e.onchange = static_cast(strtoul(row[3], nullptr, 10)); + e.onchange = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.name = row[4] ? row[4] : ""; all_entries.push_back(e); @@ -358,6 +359,70 @@ 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 SpawnConditions &e + ) + { + std::vector v; + + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.value)); + v.push_back(std::to_string(e.onchange)); + v.push_back("'" + Strings::Escape(e.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 &entries + ) + { + std::vector insert_chunks; + + for (auto &e: entries) { + std::vector v; + + v.push_back("'" + Strings::Escape(e.zone) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.value)); + v.push_back(std::to_string(e.onchange)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + + 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_SPAWN_CONDITIONS_REPOSITORY_H diff --git a/common/repositories/base/base_spawn_events_repository.h b/common/repositories/base/base_spawn_events_repository.h index d894ba1f7..3279e3430 100644 --- a/common/repositories/base/base_spawn_events_repository.h +++ b/common/repositories/base/base_spawn_events_repository.h @@ -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_SPAWN_EVENTS_REPOSITORY_H @@ -156,8 +156,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spawn_events_id ) ); @@ -166,18 +167,18 @@ public: if (results.RowCount() == 1) { SpawnEvents e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.cond_id = static_cast(strtoul(row[2], nullptr, 10)); + e.cond_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.name = row[3] ? row[3] : ""; - e.period = static_cast(strtoul(row[4], nullptr, 10)); - e.next_minute = static_cast(strtoul(row[5], nullptr, 10)); - e.next_hour = static_cast(strtoul(row[6], nullptr, 10)); - e.next_day = static_cast(strtoul(row[7], nullptr, 10)); - e.next_month = static_cast(strtoul(row[8], nullptr, 10)); - e.next_year = static_cast(strtoul(row[9], nullptr, 10)); + e.period = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.next_minute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.next_hour = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.next_day = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.next_month = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.next_year = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.enabled = static_cast(atoi(row[10])); - e.action = static_cast(strtoul(row[11], nullptr, 10)); + e.action = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.argument = static_cast(atoi(row[12])); e.strict = static_cast(atoi(row[13])); @@ -337,18 +338,18 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpawnEvents e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.cond_id = static_cast(strtoul(row[2], nullptr, 10)); + e.cond_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.name = row[3] ? row[3] : ""; - e.period = static_cast(strtoul(row[4], nullptr, 10)); - e.next_minute = static_cast(strtoul(row[5], nullptr, 10)); - e.next_hour = static_cast(strtoul(row[6], nullptr, 10)); - e.next_day = static_cast(strtoul(row[7], nullptr, 10)); - e.next_month = static_cast(strtoul(row[8], nullptr, 10)); - e.next_year = static_cast(strtoul(row[9], nullptr, 10)); + e.period = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.next_minute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.next_hour = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.next_day = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.next_month = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.next_year = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.enabled = static_cast(atoi(row[10])); - e.action = static_cast(strtoul(row[11], nullptr, 10)); + e.action = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.argument = static_cast(atoi(row[12])); e.strict = static_cast(atoi(row[13])); @@ -375,18 +376,18 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpawnEvents e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.zone = row[1] ? row[1] : ""; - e.cond_id = static_cast(strtoul(row[2], nullptr, 10)); + e.cond_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.name = row[3] ? row[3] : ""; - e.period = static_cast(strtoul(row[4], nullptr, 10)); - e.next_minute = static_cast(strtoul(row[5], nullptr, 10)); - e.next_hour = static_cast(strtoul(row[6], nullptr, 10)); - e.next_day = static_cast(strtoul(row[7], nullptr, 10)); - e.next_month = static_cast(strtoul(row[8], nullptr, 10)); - e.next_year = static_cast(strtoul(row[9], nullptr, 10)); + e.period = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.next_minute = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.next_hour = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; + e.next_day = row[7] ? static_cast(strtoul(row[7], nullptr, 10)) : 0; + e.next_month = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; + e.next_year = row[9] ? static_cast(strtoul(row[9], nullptr, 10)) : 0; e.enabled = static_cast(atoi(row[10])); - e.action = static_cast(strtoul(row[11], nullptr, 10)); + e.action = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 0; e.argument = static_cast(atoi(row[12])); e.strict = static_cast(atoi(row[13])); @@ -447,6 +448,88 @@ 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 SpawnEvents &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.cond_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.period)); + v.push_back(std::to_string(e.next_minute)); + v.push_back(std::to_string(e.next_hour)); + v.push_back(std::to_string(e.next_day)); + v.push_back(std::to_string(e.next_month)); + v.push_back(std::to_string(e.next_year)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.action)); + v.push_back(std::to_string(e.argument)); + v.push_back(std::to_string(e.strict)); + + 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.cond_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.period)); + v.push_back(std::to_string(e.next_minute)); + v.push_back(std::to_string(e.next_hour)); + v.push_back(std::to_string(e.next_day)); + v.push_back(std::to_string(e.next_month)); + v.push_back(std::to_string(e.next_year)); + v.push_back(std::to_string(e.enabled)); + v.push_back(std::to_string(e.action)); + v.push_back(std::to_string(e.argument)); + v.push_back(std::to_string(e.strict)); + + 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_SPAWN_EVENTS_REPOSITORY_H diff --git a/common/repositories/base/base_spawnentry_repository.h b/common/repositories/base/base_spawnentry_repository.h index 99f6c2ae0..4cf92d0fb 100644 --- a/common/repositories/base/base_spawnentry_repository.h +++ b/common/repositories/base/base_spawnentry_repository.h @@ -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_SPAWNENTRY_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseSpawnentryRepository { public: struct Spawnentry { @@ -410,6 +409,80 @@ 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 Spawnentry &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.spawngroupID)); + v.push_back(std::to_string(e.npcID)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.condition_value_filter)); + v.push_back(std::to_string(e.min_time)); + v.push_back(std::to_string(e.max_time)); + 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) + "'"); + + 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.spawngroupID)); + v.push_back(std::to_string(e.npcID)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.condition_value_filter)); + v.push_back(std::to_string(e.min_time)); + v.push_back(std::to_string(e.max_time)); + 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) + "'"); + + 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_SPAWNENTRY_REPOSITORY_H diff --git a/common/repositories/base/base_spawngroup_repository.h b/common/repositories/base/base_spawngroup_repository.h index 16c1931b7..4b408405a 100644 --- a/common/repositories/base/base_spawngroup_repository.h +++ b/common/repositories/base/base_spawngroup_repository.h @@ -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_SPAWNGROUP_REPOSITORY_H @@ -152,8 +152,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spawngroup_id ) ); @@ -165,16 +166,16 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.spawn_limit = static_cast(atoi(row[2])); - e.dist = strtof(row[3], nullptr); - e.max_x = strtof(row[4], nullptr); - e.min_x = strtof(row[5], nullptr); - e.max_y = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); + e.dist = row[3] ? strtof(row[3], nullptr) : 0; + e.max_x = row[4] ? strtof(row[4], nullptr) : 0; + e.min_x = row[5] ? strtof(row[5], nullptr) : 0; + e.max_y = row[6] ? strtof(row[6], nullptr) : 0; + e.min_y = row[7] ? strtof(row[7], nullptr) : 0; e.delay = static_cast(atoi(row[8])); e.mindelay = static_cast(atoi(row[9])); e.despawn = static_cast(atoi(row[10])); e.despawn_timer = static_cast(atoi(row[11])); - e.wp_spawns = static_cast(strtoul(row[12], nullptr, 10)); + e.wp_spawns = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; return e; } @@ -332,16 +333,16 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.spawn_limit = static_cast(atoi(row[2])); - e.dist = strtof(row[3], nullptr); - e.max_x = strtof(row[4], nullptr); - e.min_x = strtof(row[5], nullptr); - e.max_y = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); + e.dist = row[3] ? strtof(row[3], nullptr) : 0; + e.max_x = row[4] ? strtof(row[4], nullptr) : 0; + e.min_x = row[5] ? strtof(row[5], nullptr) : 0; + e.max_y = row[6] ? strtof(row[6], nullptr) : 0; + e.min_y = row[7] ? strtof(row[7], nullptr) : 0; e.delay = static_cast(atoi(row[8])); e.mindelay = static_cast(atoi(row[9])); e.despawn = static_cast(atoi(row[10])); e.despawn_timer = static_cast(atoi(row[11])); - e.wp_spawns = static_cast(strtoul(row[12], nullptr, 10)); + e.wp_spawns = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -369,16 +370,16 @@ public: e.id = static_cast(atoi(row[0])); e.name = row[1] ? row[1] : ""; e.spawn_limit = static_cast(atoi(row[2])); - e.dist = strtof(row[3], nullptr); - e.max_x = strtof(row[4], nullptr); - e.min_x = strtof(row[5], nullptr); - e.max_y = strtof(row[6], nullptr); - e.min_y = strtof(row[7], nullptr); + e.dist = row[3] ? strtof(row[3], nullptr) : 0; + e.max_x = row[4] ? strtof(row[4], nullptr) : 0; + e.min_x = row[5] ? strtof(row[5], nullptr) : 0; + e.max_y = row[6] ? strtof(row[6], nullptr) : 0; + e.min_y = row[7] ? strtof(row[7], nullptr) : 0; e.delay = static_cast(atoi(row[8])); e.mindelay = static_cast(atoi(row[9])); e.despawn = static_cast(atoi(row[10])); e.despawn_timer = static_cast(atoi(row[11])); - e.wp_spawns = static_cast(strtoul(row[12], nullptr, 10)); + e.wp_spawns = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -437,6 +438,86 @@ 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 Spawngroup &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.spawn_limit)); + v.push_back(std::to_string(e.dist)); + v.push_back(std::to_string(e.max_x)); + v.push_back(std::to_string(e.min_x)); + v.push_back(std::to_string(e.max_y)); + v.push_back(std::to_string(e.min_y)); + v.push_back(std::to_string(e.delay)); + v.push_back(std::to_string(e.mindelay)); + v.push_back(std::to_string(e.despawn)); + v.push_back(std::to_string(e.despawn_timer)); + v.push_back(std::to_string(e.wp_spawns)); + + 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.name) + "'"); + v.push_back(std::to_string(e.spawn_limit)); + v.push_back(std::to_string(e.dist)); + v.push_back(std::to_string(e.max_x)); + v.push_back(std::to_string(e.min_x)); + v.push_back(std::to_string(e.max_y)); + v.push_back(std::to_string(e.min_y)); + v.push_back(std::to_string(e.delay)); + v.push_back(std::to_string(e.mindelay)); + v.push_back(std::to_string(e.despawn)); + v.push_back(std::to_string(e.despawn_timer)); + v.push_back(std::to_string(e.wp_spawns)); + + 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_SPAWNGROUP_REPOSITORY_H diff --git a/common/repositories/base/base_spell_buckets_repository.h b/common/repositories/base/base_spell_buckets_repository.h index a9c78953a..c73931a39 100644 --- a/common/repositories/base/base_spell_buckets_repository.h +++ b/common/repositories/base/base_spell_buckets_repository.h @@ -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_SPELL_BUCKETS_REPOSITORY_H @@ -20,7 +20,7 @@ class BaseSpellBucketsRepository { public: struct SpellBuckets { uint64_t spellid; - std::string key; + std::string key_; std::string value; }; @@ -33,7 +33,7 @@ public: { return { "spellid", - "key", + "`key`", "value", }; } @@ -42,7 +42,7 @@ public: { return { "spellid", - "key", + "`key`", "value", }; } @@ -85,7 +85,7 @@ public: SpellBuckets e{}; e.spellid = 0; - e.key = ""; + e.key_ = ""; e.value = ""; return e; @@ -112,8 +112,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spell_buckets_id ) ); @@ -122,8 +123,8 @@ public: if (results.RowCount() == 1) { SpellBuckets e{}; - e.spellid = strtoull(row[0], nullptr, 10); - e.key = row[1] ? row[1] : ""; + e.spellid = row[0] ? strtoull(row[0], nullptr, 10) : 0; + e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; return e; @@ -159,7 +160,7 @@ public: auto columns = Columns(); v.push_back(columns[0] + " = " + std::to_string(e.spellid)); - v.push_back(columns[1] + " = '" + Strings::Escape(e.key) + "'"); + v.push_back(columns[1] + " = '" + Strings::Escape(e.key_) + "'"); v.push_back(columns[2] + " = '" + Strings::Escape(e.value) + "'"); auto results = db.QueryDatabase( @@ -183,7 +184,7 @@ public: std::vector v; v.push_back(std::to_string(e.spellid)); - v.push_back("'" + Strings::Escape(e.key) + "'"); + v.push_back("'" + Strings::Escape(e.key_) + "'"); v.push_back("'" + Strings::Escape(e.value) + "'"); auto results = db.QueryDatabase( @@ -215,7 +216,7 @@ public: std::vector v; v.push_back(std::to_string(e.spellid)); - v.push_back("'" + Strings::Escape(e.key) + "'"); + v.push_back("'" + Strings::Escape(e.key_) + "'"); v.push_back("'" + Strings::Escape(e.value) + "'"); insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); @@ -250,8 +251,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpellBuckets e{}; - e.spellid = strtoull(row[0], nullptr, 10); - e.key = row[1] ? row[1] : ""; + e.spellid = row[0] ? strtoull(row[0], nullptr, 10) : 0; + e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; all_entries.push_back(e); @@ -277,8 +278,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { SpellBuckets e{}; - e.spellid = strtoull(row[0], nullptr, 10); - e.key = row[1] ? row[1] : ""; + e.spellid = row[0] ? strtoull(row[0], nullptr, 10) : 0; + e.key_ = row[1] ? row[1] : ""; e.value = row[2] ? row[2] : ""; all_entries.push_back(e); @@ -338,6 +339,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 SpellBuckets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.spellid)); + v.push_back("'" + Strings::Escape(e.key_) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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.spellid)); + v.push_back("'" + Strings::Escape(e.key_) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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_SPELL_BUCKETS_REPOSITORY_H diff --git a/common/repositories/base/base_spell_globals_repository.h b/common/repositories/base/base_spell_globals_repository.h index a7a0541df..a3aa9c4d6 100644 --- a/common/repositories/base/base_spell_globals_repository.h +++ b/common/repositories/base/base_spell_globals_repository.h @@ -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_SPELL_GLOBALS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spell_globals_id ) ); @@ -348,6 +349,68 @@ 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 SpellGlobals &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.spellid)); + v.push_back("'" + Strings::Escape(e.spell_name) + "'"); + v.push_back("'" + Strings::Escape(e.qglobal) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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.spellid)); + v.push_back("'" + Strings::Escape(e.spell_name) + "'"); + v.push_back("'" + Strings::Escape(e.qglobal) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + + 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_SPELL_GLOBALS_REPOSITORY_H diff --git a/common/repositories/base/base_spells_new_repository.h b/common/repositories/base/base_spells_new_repository.h index 1c61aab1f..47c65ebf5 100644 --- a/common/repositories/base/base_spells_new_repository.h +++ b/common/repositories/base/base_spells_new_repository.h @@ -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_SPELLS_NEW_REPOSITORY_H @@ -28,7 +28,7 @@ public: std::string cast_on_you; std::string cast_on_other; std::string spell_fades; - int32_t range; + int32_t range_; int32_t aoerange; int32_t pushback; int32_t pushup; @@ -275,7 +275,7 @@ public: "cast_on_you", "cast_on_other", "spell_fades", - "range", + "`range`", "aoerange", "pushback", "pushup", @@ -518,7 +518,7 @@ public: "cast_on_you", "cast_on_other", "spell_fades", - "range", + "`range`", "aoerange", "pushback", "pushup", @@ -795,7 +795,7 @@ public: e.cast_on_you = ""; e.cast_on_other = ""; e.spell_fades = ""; - e.range = 100; + e.range_ = 100; e.aoerange = 0; e.pushback = 0; e.pushup = 0; @@ -1048,8 +1048,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), spells_new_id ) ); @@ -1067,7 +1068,7 @@ public: e.cast_on_you = row[6] ? row[6] : ""; e.cast_on_other = row[7] ? row[7] : ""; e.spell_fades = row[8] ? row[8] : ""; - e.range = static_cast(atoi(row[9])); + e.range_ = static_cast(atoi(row[9])); e.aoerange = static_cast(atoi(row[10])); e.pushback = static_cast(atoi(row[11])); e.pushup = static_cast(atoi(row[12])); @@ -1285,10 +1286,10 @@ public: e.persistdeath = static_cast(atoi(row[224])); e.field225 = static_cast(atoi(row[225])); e.field226 = static_cast(atoi(row[226])); - e.min_dist = strtof(row[227], nullptr); - e.min_dist_mod = strtof(row[228], nullptr); - e.max_dist = strtof(row[229], nullptr); - e.max_dist_mod = strtof(row[230], nullptr); + e.min_dist = row[227] ? strtof(row[227], nullptr) : 0; + e.min_dist_mod = row[228] ? strtof(row[228], nullptr) : 0; + e.max_dist = row[229] ? strtof(row[229], nullptr) : 0; + e.max_dist_mod = row[230] ? strtof(row[230], nullptr) : 0; e.min_range = static_cast(atoi(row[231])); e.field232 = static_cast(atoi(row[232])); e.field233 = static_cast(atoi(row[233])); @@ -1337,7 +1338,7 @@ public: v.push_back(columns[6] + " = '" + Strings::Escape(e.cast_on_you) + "'"); v.push_back(columns[7] + " = '" + Strings::Escape(e.cast_on_other) + "'"); v.push_back(columns[8] + " = '" + Strings::Escape(e.spell_fades) + "'"); - v.push_back(columns[9] + " = " + std::to_string(e.range)); + v.push_back(columns[9] + " = " + std::to_string(e.range_)); v.push_back(columns[10] + " = " + std::to_string(e.aoerange)); v.push_back(columns[11] + " = " + std::to_string(e.pushback)); v.push_back(columns[12] + " = " + std::to_string(e.pushup)); @@ -1595,7 +1596,7 @@ public: v.push_back("'" + Strings::Escape(e.cast_on_you) + "'"); v.push_back("'" + Strings::Escape(e.cast_on_other) + "'"); v.push_back("'" + Strings::Escape(e.spell_fades) + "'"); - v.push_back(std::to_string(e.range)); + v.push_back(std::to_string(e.range_)); v.push_back(std::to_string(e.aoerange)); v.push_back(std::to_string(e.pushback)); v.push_back(std::to_string(e.pushup)); @@ -1861,7 +1862,7 @@ public: v.push_back("'" + Strings::Escape(e.cast_on_you) + "'"); v.push_back("'" + Strings::Escape(e.cast_on_other) + "'"); v.push_back("'" + Strings::Escape(e.spell_fades) + "'"); - v.push_back(std::to_string(e.range)); + v.push_back(std::to_string(e.range_)); v.push_back(std::to_string(e.aoerange)); v.push_back(std::to_string(e.pushback)); v.push_back(std::to_string(e.pushup)); @@ -2131,7 +2132,7 @@ public: e.cast_on_you = row[6] ? row[6] : ""; e.cast_on_other = row[7] ? row[7] : ""; e.spell_fades = row[8] ? row[8] : ""; - e.range = static_cast(atoi(row[9])); + e.range_ = static_cast(atoi(row[9])); e.aoerange = static_cast(atoi(row[10])); e.pushback = static_cast(atoi(row[11])); e.pushup = static_cast(atoi(row[12])); @@ -2349,10 +2350,10 @@ public: e.persistdeath = static_cast(atoi(row[224])); e.field225 = static_cast(atoi(row[225])); e.field226 = static_cast(atoi(row[226])); - e.min_dist = strtof(row[227], nullptr); - e.min_dist_mod = strtof(row[228], nullptr); - e.max_dist = strtof(row[229], nullptr); - e.max_dist_mod = strtof(row[230], nullptr); + e.min_dist = row[227] ? strtof(row[227], nullptr) : 0; + e.min_dist_mod = row[228] ? strtof(row[228], nullptr) : 0; + e.max_dist = row[229] ? strtof(row[229], nullptr) : 0; + e.max_dist_mod = row[230] ? strtof(row[230], nullptr) : 0; e.min_range = static_cast(atoi(row[231])); e.field232 = static_cast(atoi(row[232])); e.field233 = static_cast(atoi(row[233])); @@ -2392,7 +2393,7 @@ public: e.cast_on_you = row[6] ? row[6] : ""; e.cast_on_other = row[7] ? row[7] : ""; e.spell_fades = row[8] ? row[8] : ""; - e.range = static_cast(atoi(row[9])); + e.range_ = static_cast(atoi(row[9])); e.aoerange = static_cast(atoi(row[10])); e.pushback = static_cast(atoi(row[11])); e.pushup = static_cast(atoi(row[12])); @@ -2610,10 +2611,10 @@ public: e.persistdeath = static_cast(atoi(row[224])); e.field225 = static_cast(atoi(row[225])); e.field226 = static_cast(atoi(row[226])); - e.min_dist = strtof(row[227], nullptr); - e.min_dist_mod = strtof(row[228], nullptr); - e.max_dist = strtof(row[229], nullptr); - e.max_dist_mod = strtof(row[230], nullptr); + e.min_dist = row[227] ? strtof(row[227], nullptr) : 0; + e.min_dist_mod = row[228] ? strtof(row[228], nullptr) : 0; + e.max_dist = row[229] ? strtof(row[229], nullptr) : 0; + e.max_dist_mod = row[230] ? strtof(row[230], nullptr) : 0; e.min_range = static_cast(atoi(row[231])); e.field232 = static_cast(atoi(row[232])); e.field233 = static_cast(atoi(row[233])); @@ -2678,6 +2679,534 @@ 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 SpellsNew &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.player_1) + "'"); + v.push_back("'" + Strings::Escape(e.teleport_zone) + "'"); + v.push_back("'" + Strings::Escape(e.you_cast) + "'"); + v.push_back("'" + Strings::Escape(e.other_casts) + "'"); + v.push_back("'" + Strings::Escape(e.cast_on_you) + "'"); + v.push_back("'" + Strings::Escape(e.cast_on_other) + "'"); + v.push_back("'" + Strings::Escape(e.spell_fades) + "'"); + v.push_back(std::to_string(e.range_)); + v.push_back(std::to_string(e.aoerange)); + v.push_back(std::to_string(e.pushback)); + v.push_back(std::to_string(e.pushup)); + v.push_back(std::to_string(e.cast_time)); + v.push_back(std::to_string(e.recovery_time)); + v.push_back(std::to_string(e.recast_time)); + v.push_back(std::to_string(e.buffdurationformula)); + v.push_back(std::to_string(e.buffduration)); + v.push_back(std::to_string(e.AEDuration)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.effect_base_value1)); + v.push_back(std::to_string(e.effect_base_value2)); + v.push_back(std::to_string(e.effect_base_value3)); + v.push_back(std::to_string(e.effect_base_value4)); + v.push_back(std::to_string(e.effect_base_value5)); + v.push_back(std::to_string(e.effect_base_value6)); + v.push_back(std::to_string(e.effect_base_value7)); + v.push_back(std::to_string(e.effect_base_value8)); + v.push_back(std::to_string(e.effect_base_value9)); + v.push_back(std::to_string(e.effect_base_value10)); + v.push_back(std::to_string(e.effect_base_value11)); + v.push_back(std::to_string(e.effect_base_value12)); + v.push_back(std::to_string(e.effect_limit_value1)); + v.push_back(std::to_string(e.effect_limit_value2)); + v.push_back(std::to_string(e.effect_limit_value3)); + v.push_back(std::to_string(e.effect_limit_value4)); + v.push_back(std::to_string(e.effect_limit_value5)); + v.push_back(std::to_string(e.effect_limit_value6)); + v.push_back(std::to_string(e.effect_limit_value7)); + v.push_back(std::to_string(e.effect_limit_value8)); + v.push_back(std::to_string(e.effect_limit_value9)); + v.push_back(std::to_string(e.effect_limit_value10)); + v.push_back(std::to_string(e.effect_limit_value11)); + v.push_back(std::to_string(e.effect_limit_value12)); + v.push_back(std::to_string(e.max1)); + v.push_back(std::to_string(e.max2)); + v.push_back(std::to_string(e.max3)); + v.push_back(std::to_string(e.max4)); + v.push_back(std::to_string(e.max5)); + v.push_back(std::to_string(e.max6)); + v.push_back(std::to_string(e.max7)); + v.push_back(std::to_string(e.max8)); + v.push_back(std::to_string(e.max9)); + v.push_back(std::to_string(e.max10)); + v.push_back(std::to_string(e.max11)); + v.push_back(std::to_string(e.max12)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.memicon)); + v.push_back(std::to_string(e.components1)); + v.push_back(std::to_string(e.components2)); + v.push_back(std::to_string(e.components3)); + v.push_back(std::to_string(e.components4)); + v.push_back(std::to_string(e.component_counts1)); + v.push_back(std::to_string(e.component_counts2)); + v.push_back(std::to_string(e.component_counts3)); + v.push_back(std::to_string(e.component_counts4)); + v.push_back(std::to_string(e.NoexpendReagent1)); + v.push_back(std::to_string(e.NoexpendReagent2)); + v.push_back(std::to_string(e.NoexpendReagent3)); + v.push_back(std::to_string(e.NoexpendReagent4)); + v.push_back(std::to_string(e.formula1)); + v.push_back(std::to_string(e.formula2)); + v.push_back(std::to_string(e.formula3)); + v.push_back(std::to_string(e.formula4)); + v.push_back(std::to_string(e.formula5)); + v.push_back(std::to_string(e.formula6)); + v.push_back(std::to_string(e.formula7)); + v.push_back(std::to_string(e.formula8)); + v.push_back(std::to_string(e.formula9)); + v.push_back(std::to_string(e.formula10)); + v.push_back(std::to_string(e.formula11)); + v.push_back(std::to_string(e.formula12)); + v.push_back(std::to_string(e.LightType)); + v.push_back(std::to_string(e.goodEffect)); + v.push_back(std::to_string(e.Activated)); + v.push_back(std::to_string(e.resisttype)); + v.push_back(std::to_string(e.effectid1)); + v.push_back(std::to_string(e.effectid2)); + v.push_back(std::to_string(e.effectid3)); + v.push_back(std::to_string(e.effectid4)); + v.push_back(std::to_string(e.effectid5)); + v.push_back(std::to_string(e.effectid6)); + v.push_back(std::to_string(e.effectid7)); + v.push_back(std::to_string(e.effectid8)); + v.push_back(std::to_string(e.effectid9)); + v.push_back(std::to_string(e.effectid10)); + v.push_back(std::to_string(e.effectid11)); + v.push_back(std::to_string(e.effectid12)); + v.push_back(std::to_string(e.targettype)); + v.push_back(std::to_string(e.basediff)); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.zonetype)); + v.push_back(std::to_string(e.EnvironmentType)); + v.push_back(std::to_string(e.TimeOfDay)); + v.push_back(std::to_string(e.classes1)); + v.push_back(std::to_string(e.classes2)); + v.push_back(std::to_string(e.classes3)); + v.push_back(std::to_string(e.classes4)); + v.push_back(std::to_string(e.classes5)); + v.push_back(std::to_string(e.classes6)); + v.push_back(std::to_string(e.classes7)); + v.push_back(std::to_string(e.classes8)); + v.push_back(std::to_string(e.classes9)); + v.push_back(std::to_string(e.classes10)); + v.push_back(std::to_string(e.classes11)); + v.push_back(std::to_string(e.classes12)); + v.push_back(std::to_string(e.classes13)); + v.push_back(std::to_string(e.classes14)); + v.push_back(std::to_string(e.classes15)); + v.push_back(std::to_string(e.classes16)); + v.push_back(std::to_string(e.CastingAnim)); + v.push_back(std::to_string(e.TargetAnim)); + v.push_back(std::to_string(e.TravelType)); + v.push_back(std::to_string(e.SpellAffectIndex)); + v.push_back(std::to_string(e.disallow_sit)); + v.push_back(std::to_string(e.deities0)); + v.push_back(std::to_string(e.deities1)); + v.push_back(std::to_string(e.deities2)); + v.push_back(std::to_string(e.deities3)); + v.push_back(std::to_string(e.deities4)); + v.push_back(std::to_string(e.deities5)); + v.push_back(std::to_string(e.deities6)); + v.push_back(std::to_string(e.deities7)); + v.push_back(std::to_string(e.deities8)); + v.push_back(std::to_string(e.deities9)); + v.push_back(std::to_string(e.deities10)); + v.push_back(std::to_string(e.deities11)); + v.push_back(std::to_string(e.deities12)); + v.push_back(std::to_string(e.deities13)); + v.push_back(std::to_string(e.deities14)); + v.push_back(std::to_string(e.deities15)); + v.push_back(std::to_string(e.deities16)); + v.push_back(std::to_string(e.field142)); + v.push_back(std::to_string(e.field143)); + v.push_back(std::to_string(e.new_icon)); + v.push_back(std::to_string(e.spellanim)); + v.push_back(std::to_string(e.uninterruptable)); + v.push_back(std::to_string(e.ResistDiff)); + v.push_back(std::to_string(e.dot_stacking_exempt)); + v.push_back(std::to_string(e.deleteable)); + v.push_back(std::to_string(e.RecourseLink)); + v.push_back(std::to_string(e.no_partial_resist)); + v.push_back(std::to_string(e.field152)); + v.push_back(std::to_string(e.field153)); + v.push_back(std::to_string(e.short_buff_box)); + v.push_back(std::to_string(e.descnum)); + v.push_back(std::to_string(e.typedescnum)); + v.push_back(std::to_string(e.effectdescnum)); + v.push_back(std::to_string(e.effectdescnum2)); + v.push_back(std::to_string(e.npc_no_los)); + v.push_back(std::to_string(e.field160)); + v.push_back(std::to_string(e.reflectable)); + v.push_back(std::to_string(e.bonushate)); + v.push_back(std::to_string(e.field163)); + v.push_back(std::to_string(e.field164)); + v.push_back(std::to_string(e.ldon_trap)); + v.push_back(std::to_string(e.EndurCost)); + v.push_back(std::to_string(e.EndurTimerIndex)); + v.push_back(std::to_string(e.IsDiscipline)); + v.push_back(std::to_string(e.field169)); + v.push_back(std::to_string(e.field170)); + v.push_back(std::to_string(e.field171)); + v.push_back(std::to_string(e.field172)); + v.push_back(std::to_string(e.HateAdded)); + v.push_back(std::to_string(e.EndurUpkeep)); + v.push_back(std::to_string(e.numhitstype)); + v.push_back(std::to_string(e.numhits)); + v.push_back(std::to_string(e.pvpresistbase)); + v.push_back(std::to_string(e.pvpresistcalc)); + v.push_back(std::to_string(e.pvpresistcap)); + v.push_back(std::to_string(e.spell_category)); + v.push_back(std::to_string(e.pvp_duration)); + v.push_back(std::to_string(e.pvp_duration_cap)); + v.push_back(std::to_string(e.pcnpc_only_flag)); + v.push_back(std::to_string(e.cast_not_standing)); + v.push_back(std::to_string(e.can_mgb)); + v.push_back(std::to_string(e.nodispell)); + v.push_back(std::to_string(e.npc_category)); + v.push_back(std::to_string(e.npc_usefulness)); + v.push_back(std::to_string(e.MinResist)); + v.push_back(std::to_string(e.MaxResist)); + v.push_back(std::to_string(e.viral_targets)); + v.push_back(std::to_string(e.viral_timer)); + v.push_back(std::to_string(e.nimbuseffect)); + v.push_back(std::to_string(e.ConeStartAngle)); + v.push_back(std::to_string(e.ConeStopAngle)); + v.push_back(std::to_string(e.sneaking)); + v.push_back(std::to_string(e.not_extendable)); + v.push_back(std::to_string(e.field198)); + v.push_back(std::to_string(e.field199)); + v.push_back(std::to_string(e.suspendable)); + v.push_back(std::to_string(e.viral_range)); + v.push_back(std::to_string(e.songcap)); + v.push_back(std::to_string(e.field203)); + v.push_back(std::to_string(e.field204)); + v.push_back(std::to_string(e.no_block)); + v.push_back(std::to_string(e.field206)); + v.push_back(std::to_string(e.spellgroup)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.field209)); + v.push_back(std::to_string(e.field210)); + v.push_back(std::to_string(e.CastRestriction)); + v.push_back(std::to_string(e.allowrest)); + v.push_back(std::to_string(e.InCombat)); + v.push_back(std::to_string(e.OutofCombat)); + v.push_back(std::to_string(e.field215)); + v.push_back(std::to_string(e.field216)); + v.push_back(std::to_string(e.field217)); + v.push_back(std::to_string(e.aemaxtargets)); + v.push_back(std::to_string(e.maxtargets)); + v.push_back(std::to_string(e.field220)); + v.push_back(std::to_string(e.field221)); + v.push_back(std::to_string(e.field222)); + v.push_back(std::to_string(e.field223)); + v.push_back(std::to_string(e.persistdeath)); + v.push_back(std::to_string(e.field225)); + v.push_back(std::to_string(e.field226)); + v.push_back(std::to_string(e.min_dist)); + v.push_back(std::to_string(e.min_dist_mod)); + v.push_back(std::to_string(e.max_dist)); + v.push_back(std::to_string(e.max_dist_mod)); + v.push_back(std::to_string(e.min_range)); + v.push_back(std::to_string(e.field232)); + v.push_back(std::to_string(e.field233)); + v.push_back(std::to_string(e.field234)); + v.push_back(std::to_string(e.field235)); + v.push_back(std::to_string(e.field236)); + + 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.name) + "'"); + v.push_back("'" + Strings::Escape(e.player_1) + "'"); + v.push_back("'" + Strings::Escape(e.teleport_zone) + "'"); + v.push_back("'" + Strings::Escape(e.you_cast) + "'"); + v.push_back("'" + Strings::Escape(e.other_casts) + "'"); + v.push_back("'" + Strings::Escape(e.cast_on_you) + "'"); + v.push_back("'" + Strings::Escape(e.cast_on_other) + "'"); + v.push_back("'" + Strings::Escape(e.spell_fades) + "'"); + v.push_back(std::to_string(e.range_)); + v.push_back(std::to_string(e.aoerange)); + v.push_back(std::to_string(e.pushback)); + v.push_back(std::to_string(e.pushup)); + v.push_back(std::to_string(e.cast_time)); + v.push_back(std::to_string(e.recovery_time)); + v.push_back(std::to_string(e.recast_time)); + v.push_back(std::to_string(e.buffdurationformula)); + v.push_back(std::to_string(e.buffduration)); + v.push_back(std::to_string(e.AEDuration)); + v.push_back(std::to_string(e.mana)); + v.push_back(std::to_string(e.effect_base_value1)); + v.push_back(std::to_string(e.effect_base_value2)); + v.push_back(std::to_string(e.effect_base_value3)); + v.push_back(std::to_string(e.effect_base_value4)); + v.push_back(std::to_string(e.effect_base_value5)); + v.push_back(std::to_string(e.effect_base_value6)); + v.push_back(std::to_string(e.effect_base_value7)); + v.push_back(std::to_string(e.effect_base_value8)); + v.push_back(std::to_string(e.effect_base_value9)); + v.push_back(std::to_string(e.effect_base_value10)); + v.push_back(std::to_string(e.effect_base_value11)); + v.push_back(std::to_string(e.effect_base_value12)); + v.push_back(std::to_string(e.effect_limit_value1)); + v.push_back(std::to_string(e.effect_limit_value2)); + v.push_back(std::to_string(e.effect_limit_value3)); + v.push_back(std::to_string(e.effect_limit_value4)); + v.push_back(std::to_string(e.effect_limit_value5)); + v.push_back(std::to_string(e.effect_limit_value6)); + v.push_back(std::to_string(e.effect_limit_value7)); + v.push_back(std::to_string(e.effect_limit_value8)); + v.push_back(std::to_string(e.effect_limit_value9)); + v.push_back(std::to_string(e.effect_limit_value10)); + v.push_back(std::to_string(e.effect_limit_value11)); + v.push_back(std::to_string(e.effect_limit_value12)); + v.push_back(std::to_string(e.max1)); + v.push_back(std::to_string(e.max2)); + v.push_back(std::to_string(e.max3)); + v.push_back(std::to_string(e.max4)); + v.push_back(std::to_string(e.max5)); + v.push_back(std::to_string(e.max6)); + v.push_back(std::to_string(e.max7)); + v.push_back(std::to_string(e.max8)); + v.push_back(std::to_string(e.max9)); + v.push_back(std::to_string(e.max10)); + v.push_back(std::to_string(e.max11)); + v.push_back(std::to_string(e.max12)); + v.push_back(std::to_string(e.icon)); + v.push_back(std::to_string(e.memicon)); + v.push_back(std::to_string(e.components1)); + v.push_back(std::to_string(e.components2)); + v.push_back(std::to_string(e.components3)); + v.push_back(std::to_string(e.components4)); + v.push_back(std::to_string(e.component_counts1)); + v.push_back(std::to_string(e.component_counts2)); + v.push_back(std::to_string(e.component_counts3)); + v.push_back(std::to_string(e.component_counts4)); + v.push_back(std::to_string(e.NoexpendReagent1)); + v.push_back(std::to_string(e.NoexpendReagent2)); + v.push_back(std::to_string(e.NoexpendReagent3)); + v.push_back(std::to_string(e.NoexpendReagent4)); + v.push_back(std::to_string(e.formula1)); + v.push_back(std::to_string(e.formula2)); + v.push_back(std::to_string(e.formula3)); + v.push_back(std::to_string(e.formula4)); + v.push_back(std::to_string(e.formula5)); + v.push_back(std::to_string(e.formula6)); + v.push_back(std::to_string(e.formula7)); + v.push_back(std::to_string(e.formula8)); + v.push_back(std::to_string(e.formula9)); + v.push_back(std::to_string(e.formula10)); + v.push_back(std::to_string(e.formula11)); + v.push_back(std::to_string(e.formula12)); + v.push_back(std::to_string(e.LightType)); + v.push_back(std::to_string(e.goodEffect)); + v.push_back(std::to_string(e.Activated)); + v.push_back(std::to_string(e.resisttype)); + v.push_back(std::to_string(e.effectid1)); + v.push_back(std::to_string(e.effectid2)); + v.push_back(std::to_string(e.effectid3)); + v.push_back(std::to_string(e.effectid4)); + v.push_back(std::to_string(e.effectid5)); + v.push_back(std::to_string(e.effectid6)); + v.push_back(std::to_string(e.effectid7)); + v.push_back(std::to_string(e.effectid8)); + v.push_back(std::to_string(e.effectid9)); + v.push_back(std::to_string(e.effectid10)); + v.push_back(std::to_string(e.effectid11)); + v.push_back(std::to_string(e.effectid12)); + v.push_back(std::to_string(e.targettype)); + v.push_back(std::to_string(e.basediff)); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.zonetype)); + v.push_back(std::to_string(e.EnvironmentType)); + v.push_back(std::to_string(e.TimeOfDay)); + v.push_back(std::to_string(e.classes1)); + v.push_back(std::to_string(e.classes2)); + v.push_back(std::to_string(e.classes3)); + v.push_back(std::to_string(e.classes4)); + v.push_back(std::to_string(e.classes5)); + v.push_back(std::to_string(e.classes6)); + v.push_back(std::to_string(e.classes7)); + v.push_back(std::to_string(e.classes8)); + v.push_back(std::to_string(e.classes9)); + v.push_back(std::to_string(e.classes10)); + v.push_back(std::to_string(e.classes11)); + v.push_back(std::to_string(e.classes12)); + v.push_back(std::to_string(e.classes13)); + v.push_back(std::to_string(e.classes14)); + v.push_back(std::to_string(e.classes15)); + v.push_back(std::to_string(e.classes16)); + v.push_back(std::to_string(e.CastingAnim)); + v.push_back(std::to_string(e.TargetAnim)); + v.push_back(std::to_string(e.TravelType)); + v.push_back(std::to_string(e.SpellAffectIndex)); + v.push_back(std::to_string(e.disallow_sit)); + v.push_back(std::to_string(e.deities0)); + v.push_back(std::to_string(e.deities1)); + v.push_back(std::to_string(e.deities2)); + v.push_back(std::to_string(e.deities3)); + v.push_back(std::to_string(e.deities4)); + v.push_back(std::to_string(e.deities5)); + v.push_back(std::to_string(e.deities6)); + v.push_back(std::to_string(e.deities7)); + v.push_back(std::to_string(e.deities8)); + v.push_back(std::to_string(e.deities9)); + v.push_back(std::to_string(e.deities10)); + v.push_back(std::to_string(e.deities11)); + v.push_back(std::to_string(e.deities12)); + v.push_back(std::to_string(e.deities13)); + v.push_back(std::to_string(e.deities14)); + v.push_back(std::to_string(e.deities15)); + v.push_back(std::to_string(e.deities16)); + v.push_back(std::to_string(e.field142)); + v.push_back(std::to_string(e.field143)); + v.push_back(std::to_string(e.new_icon)); + v.push_back(std::to_string(e.spellanim)); + v.push_back(std::to_string(e.uninterruptable)); + v.push_back(std::to_string(e.ResistDiff)); + v.push_back(std::to_string(e.dot_stacking_exempt)); + v.push_back(std::to_string(e.deleteable)); + v.push_back(std::to_string(e.RecourseLink)); + v.push_back(std::to_string(e.no_partial_resist)); + v.push_back(std::to_string(e.field152)); + v.push_back(std::to_string(e.field153)); + v.push_back(std::to_string(e.short_buff_box)); + v.push_back(std::to_string(e.descnum)); + v.push_back(std::to_string(e.typedescnum)); + v.push_back(std::to_string(e.effectdescnum)); + v.push_back(std::to_string(e.effectdescnum2)); + v.push_back(std::to_string(e.npc_no_los)); + v.push_back(std::to_string(e.field160)); + v.push_back(std::to_string(e.reflectable)); + v.push_back(std::to_string(e.bonushate)); + v.push_back(std::to_string(e.field163)); + v.push_back(std::to_string(e.field164)); + v.push_back(std::to_string(e.ldon_trap)); + v.push_back(std::to_string(e.EndurCost)); + v.push_back(std::to_string(e.EndurTimerIndex)); + v.push_back(std::to_string(e.IsDiscipline)); + v.push_back(std::to_string(e.field169)); + v.push_back(std::to_string(e.field170)); + v.push_back(std::to_string(e.field171)); + v.push_back(std::to_string(e.field172)); + v.push_back(std::to_string(e.HateAdded)); + v.push_back(std::to_string(e.EndurUpkeep)); + v.push_back(std::to_string(e.numhitstype)); + v.push_back(std::to_string(e.numhits)); + v.push_back(std::to_string(e.pvpresistbase)); + v.push_back(std::to_string(e.pvpresistcalc)); + v.push_back(std::to_string(e.pvpresistcap)); + v.push_back(std::to_string(e.spell_category)); + v.push_back(std::to_string(e.pvp_duration)); + v.push_back(std::to_string(e.pvp_duration_cap)); + v.push_back(std::to_string(e.pcnpc_only_flag)); + v.push_back(std::to_string(e.cast_not_standing)); + v.push_back(std::to_string(e.can_mgb)); + v.push_back(std::to_string(e.nodispell)); + v.push_back(std::to_string(e.npc_category)); + v.push_back(std::to_string(e.npc_usefulness)); + v.push_back(std::to_string(e.MinResist)); + v.push_back(std::to_string(e.MaxResist)); + v.push_back(std::to_string(e.viral_targets)); + v.push_back(std::to_string(e.viral_timer)); + v.push_back(std::to_string(e.nimbuseffect)); + v.push_back(std::to_string(e.ConeStartAngle)); + v.push_back(std::to_string(e.ConeStopAngle)); + v.push_back(std::to_string(e.sneaking)); + v.push_back(std::to_string(e.not_extendable)); + v.push_back(std::to_string(e.field198)); + v.push_back(std::to_string(e.field199)); + v.push_back(std::to_string(e.suspendable)); + v.push_back(std::to_string(e.viral_range)); + v.push_back(std::to_string(e.songcap)); + v.push_back(std::to_string(e.field203)); + v.push_back(std::to_string(e.field204)); + v.push_back(std::to_string(e.no_block)); + v.push_back(std::to_string(e.field206)); + v.push_back(std::to_string(e.spellgroup)); + v.push_back(std::to_string(e.rank)); + v.push_back(std::to_string(e.field209)); + v.push_back(std::to_string(e.field210)); + v.push_back(std::to_string(e.CastRestriction)); + v.push_back(std::to_string(e.allowrest)); + v.push_back(std::to_string(e.InCombat)); + v.push_back(std::to_string(e.OutofCombat)); + v.push_back(std::to_string(e.field215)); + v.push_back(std::to_string(e.field216)); + v.push_back(std::to_string(e.field217)); + v.push_back(std::to_string(e.aemaxtargets)); + v.push_back(std::to_string(e.maxtargets)); + v.push_back(std::to_string(e.field220)); + v.push_back(std::to_string(e.field221)); + v.push_back(std::to_string(e.field222)); + v.push_back(std::to_string(e.field223)); + v.push_back(std::to_string(e.persistdeath)); + v.push_back(std::to_string(e.field225)); + v.push_back(std::to_string(e.field226)); + v.push_back(std::to_string(e.min_dist)); + v.push_back(std::to_string(e.min_dist_mod)); + v.push_back(std::to_string(e.max_dist)); + v.push_back(std::to_string(e.max_dist_mod)); + v.push_back(std::to_string(e.min_range)); + v.push_back(std::to_string(e.field232)); + v.push_back(std::to_string(e.field233)); + v.push_back(std::to_string(e.field234)); + v.push_back(std::to_string(e.field235)); + v.push_back(std::to_string(e.field236)); + + 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_SPELLS_NEW_REPOSITORY_H diff --git a/common/repositories/base/base_start_zones_repository.h b/common/repositories/base/base_start_zones_repository.h index 124ff9ecb..df54438ee 100644 --- a/common/repositories/base/base_start_zones_repository.h +++ b/common/repositories/base/base_start_zones_repository.h @@ -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_START_ZONES_REPOSITORY_H @@ -176,8 +176,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), start_zones_id ) ); @@ -186,10 +187,10 @@ public: if (results.RowCount() == 1) { StartZones e{}; - e.x = strtof(row[0], nullptr); - e.y = strtof(row[1], nullptr); - e.z = strtof(row[2], nullptr); - e.heading = strtof(row[3], nullptr); + e.x = row[0] ? strtof(row[0], nullptr) : 0; + e.y = row[1] ? strtof(row[1], nullptr) : 0; + e.z = row[2] ? strtof(row[2], nullptr) : 0; + e.heading = row[3] ? strtof(row[3], nullptr) : 0; e.zone_id = static_cast(atoi(row[4])); e.bind_id = static_cast(atoi(row[5])); e.player_choice = static_cast(atoi(row[6])); @@ -197,10 +198,10 @@ public: e.player_deity = static_cast(atoi(row[8])); e.player_race = static_cast(atoi(row[9])); e.start_zone = static_cast(atoi(row[10])); - e.bind_x = strtof(row[11], nullptr); - e.bind_y = strtof(row[12], nullptr); - e.bind_z = strtof(row[13], nullptr); - e.select_rank = static_cast(strtoul(row[14], nullptr, 10)); + e.bind_x = row[11] ? strtof(row[11], nullptr) : 0; + e.bind_y = row[12] ? strtof(row[12], nullptr) : 0; + e.bind_z = row[13] ? strtof(row[13], nullptr) : 0; + e.select_rank = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 50; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -378,10 +379,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { StartZones e{}; - e.x = strtof(row[0], nullptr); - e.y = strtof(row[1], nullptr); - e.z = strtof(row[2], nullptr); - e.heading = strtof(row[3], nullptr); + e.x = row[0] ? strtof(row[0], nullptr) : 0; + e.y = row[1] ? strtof(row[1], nullptr) : 0; + e.z = row[2] ? strtof(row[2], nullptr) : 0; + e.heading = row[3] ? strtof(row[3], nullptr) : 0; e.zone_id = static_cast(atoi(row[4])); e.bind_id = static_cast(atoi(row[5])); e.player_choice = static_cast(atoi(row[6])); @@ -389,10 +390,10 @@ public: e.player_deity = static_cast(atoi(row[8])); e.player_race = static_cast(atoi(row[9])); e.start_zone = static_cast(atoi(row[10])); - e.bind_x = strtof(row[11], nullptr); - e.bind_y = strtof(row[12], nullptr); - e.bind_z = strtof(row[13], nullptr); - e.select_rank = static_cast(strtoul(row[14], nullptr, 10)); + e.bind_x = row[11] ? strtof(row[11], nullptr) : 0; + e.bind_y = row[12] ? strtof(row[12], nullptr) : 0; + e.bind_z = row[13] ? strtof(row[13], nullptr) : 0; + e.select_rank = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 50; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -421,10 +422,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { StartZones e{}; - e.x = strtof(row[0], nullptr); - e.y = strtof(row[1], nullptr); - e.z = strtof(row[2], nullptr); - e.heading = strtof(row[3], nullptr); + e.x = row[0] ? strtof(row[0], nullptr) : 0; + e.y = row[1] ? strtof(row[1], nullptr) : 0; + e.z = row[2] ? strtof(row[2], nullptr) : 0; + e.heading = row[3] ? strtof(row[3], nullptr) : 0; e.zone_id = static_cast(atoi(row[4])); e.bind_id = static_cast(atoi(row[5])); e.player_choice = static_cast(atoi(row[6])); @@ -432,10 +433,10 @@ public: e.player_deity = static_cast(atoi(row[8])); e.player_race = static_cast(atoi(row[9])); e.start_zone = static_cast(atoi(row[10])); - e.bind_x = strtof(row[11], nullptr); - e.bind_y = strtof(row[12], nullptr); - e.bind_z = strtof(row[13], nullptr); - e.select_rank = static_cast(strtoul(row[14], nullptr, 10)); + e.bind_x = row[11] ? strtof(row[11], nullptr) : 0; + e.bind_y = row[12] ? strtof(row[12], nullptr) : 0; + e.bind_z = row[13] ? strtof(row[13], nullptr) : 0; + e.select_rank = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 50; e.min_expansion = static_cast(atoi(row[15])); e.max_expansion = static_cast(atoi(row[16])); e.content_flags = row[17] ? row[17] : ""; @@ -498,6 +499,98 @@ 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 StartZones &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.bind_id)); + v.push_back(std::to_string(e.player_choice)); + v.push_back(std::to_string(e.player_class)); + v.push_back(std::to_string(e.player_deity)); + v.push_back(std::to_string(e.player_race)); + v.push_back(std::to_string(e.start_zone)); + v.push_back(std::to_string(e.bind_x)); + v.push_back(std::to_string(e.bind_y)); + v.push_back(std::to_string(e.bind_z)); + v.push_back(std::to_string(e.select_rank)); + 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) + "'"); + + 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.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.zone_id)); + v.push_back(std::to_string(e.bind_id)); + v.push_back(std::to_string(e.player_choice)); + v.push_back(std::to_string(e.player_class)); + v.push_back(std::to_string(e.player_deity)); + v.push_back(std::to_string(e.player_race)); + v.push_back(std::to_string(e.start_zone)); + v.push_back(std::to_string(e.bind_x)); + v.push_back(std::to_string(e.bind_y)); + v.push_back(std::to_string(e.bind_z)); + v.push_back(std::to_string(e.select_rank)); + 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) + "'"); + + 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_START_ZONES_REPOSITORY_H diff --git a/common/repositories/base/base_starting_items_repository.h b/common/repositories/base/base_starting_items_repository.h index e2d8d4221..8c48bb65e 100644 --- a/common/repositories/base/base_starting_items_repository.h +++ b/common/repositories/base/base_starting_items_repository.h @@ -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_STARTING_ITEMS_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseStartingItemsRepository { public: struct StartingItems { @@ -164,13 +163,13 @@ public: if (results.RowCount() == 1) { StartingItems e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.class_list = row[1] ? row[1] : ""; e.race_list = row[2] ? row[2] : ""; e.deity_list = row[3] ? row[3] : ""; e.zone_id_list = row[4] ? row[4] : ""; - e.item_id = static_cast(strtoul(row[5], nullptr, 10)); - e.item_charges = static_cast(strtoul(row[6], nullptr, 10)); + e.item_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.item_charges = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 1; e.status = static_cast(atoi(row[7])); e.inventory_slot = static_cast(atoi(row[8])); e.min_expansion = static_cast(atoi(row[9])); @@ -331,13 +330,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { StartingItems e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.class_list = row[1] ? row[1] : ""; e.race_list = row[2] ? row[2] : ""; e.deity_list = row[3] ? row[3] : ""; e.zone_id_list = row[4] ? row[4] : ""; - e.item_id = static_cast(strtoul(row[5], nullptr, 10)); - e.item_charges = static_cast(strtoul(row[6], nullptr, 10)); + e.item_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.item_charges = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 1; e.status = static_cast(atoi(row[7])); e.inventory_slot = static_cast(atoi(row[8])); e.min_expansion = static_cast(atoi(row[9])); @@ -368,13 +367,13 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { StartingItems e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.class_list = row[1] ? row[1] : ""; e.race_list = row[2] ? row[2] : ""; e.deity_list = row[3] ? row[3] : ""; e.zone_id_list = row[4] ? row[4] : ""; - e.item_id = static_cast(strtoul(row[5], nullptr, 10)); - e.item_charges = static_cast(strtoul(row[6], nullptr, 10)); + e.item_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; + e.item_charges = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 1; e.status = static_cast(atoi(row[7])); e.inventory_slot = static_cast(atoi(row[8])); e.min_expansion = static_cast(atoi(row[9])); @@ -439,6 +438,86 @@ 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 StartingItems &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.class_list) + "'"); + v.push_back("'" + Strings::Escape(e.race_list) + "'"); + v.push_back("'" + Strings::Escape(e.deity_list) + "'"); + v.push_back("'" + Strings::Escape(e.zone_id_list) + "'"); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.item_charges)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.inventory_slot)); + 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) + "'"); + + 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.class_list) + "'"); + v.push_back("'" + Strings::Escape(e.race_list) + "'"); + v.push_back("'" + Strings::Escape(e.deity_list) + "'"); + v.push_back("'" + Strings::Escape(e.zone_id_list) + "'"); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.item_charges)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.inventory_slot)); + 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) + "'"); + + 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_STARTING_ITEMS_REPOSITORY_H diff --git a/common/repositories/base/base_task_activities_repository.h b/common/repositories/base/base_task_activities_repository.h index 798a9d5ba..e8cb02939 100644 --- a/common/repositories/base/base_task_activities_repository.h +++ b/common/repositories/base/base_task_activities_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseTaskActivitiesRepository { public: struct TaskActivities { @@ -212,31 +211,31 @@ public: if (results.RowCount() == 1) { TaskActivities e{}; - e.taskid = static_cast(strtoul(row[0], nullptr, 10)); - e.activityid = static_cast(strtoul(row[1], nullptr, 10)); + e.taskid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.activityid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.req_activity_id = static_cast(atoi(row[2])); e.step = static_cast(atoi(row[3])); - e.activitytype = static_cast(strtoul(row[4], nullptr, 10)); + e.activitytype = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.target_name = row[5] ? row[5] : ""; - e.goalmethod = static_cast(strtoul(row[6], nullptr, 10)); + e.goalmethod = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; e.goalcount = static_cast(atoi(row[7])); e.description_override = row[8] ? row[8] : ""; e.npc_match_list = row[9] ? row[9] : ""; e.item_id_list = row[10] ? row[10] : ""; e.item_list = row[11] ? row[11] : ""; e.dz_switch_id = static_cast(atoi(row[12])); - e.min_x = strtof(row[13], nullptr); - e.min_y = strtof(row[14], nullptr); - e.min_z = strtof(row[15], nullptr); - e.max_x = strtof(row[16], nullptr); - e.max_y = strtof(row[17], nullptr); - e.max_z = strtof(row[18], nullptr); + e.min_x = row[13] ? strtof(row[13], nullptr) : 0; + e.min_y = row[14] ? strtof(row[14], nullptr) : 0; + e.min_z = row[15] ? strtof(row[15], nullptr) : 0; + e.max_x = row[16] ? strtof(row[16], nullptr) : 0; + e.max_y = row[17] ? strtof(row[17], nullptr) : 0; + e.max_z = row[18] ? strtof(row[18], nullptr) : 0; e.skill_list = row[19] ? row[19] : ""; e.spell_list = row[20] ? row[20] : ""; e.zones = row[21] ? row[21] : ""; e.zone_version = static_cast(atoi(row[22])); e.optional = static_cast(atoi(row[23])); - e.list_group = static_cast(strtoul(row[24], nullptr, 10)); + e.list_group = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; return e; } @@ -428,31 +427,31 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { TaskActivities e{}; - e.taskid = static_cast(strtoul(row[0], nullptr, 10)); - e.activityid = static_cast(strtoul(row[1], nullptr, 10)); + e.taskid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.activityid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.req_activity_id = static_cast(atoi(row[2])); e.step = static_cast(atoi(row[3])); - e.activitytype = static_cast(strtoul(row[4], nullptr, 10)); + e.activitytype = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.target_name = row[5] ? row[5] : ""; - e.goalmethod = static_cast(strtoul(row[6], nullptr, 10)); + e.goalmethod = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; e.goalcount = static_cast(atoi(row[7])); e.description_override = row[8] ? row[8] : ""; e.npc_match_list = row[9] ? row[9] : ""; e.item_id_list = row[10] ? row[10] : ""; e.item_list = row[11] ? row[11] : ""; e.dz_switch_id = static_cast(atoi(row[12])); - e.min_x = strtof(row[13], nullptr); - e.min_y = strtof(row[14], nullptr); - e.min_z = strtof(row[15], nullptr); - e.max_x = strtof(row[16], nullptr); - e.max_y = strtof(row[17], nullptr); - e.max_z = strtof(row[18], nullptr); + e.min_x = row[13] ? strtof(row[13], nullptr) : 0; + e.min_y = row[14] ? strtof(row[14], nullptr) : 0; + e.min_z = row[15] ? strtof(row[15], nullptr) : 0; + e.max_x = row[16] ? strtof(row[16], nullptr) : 0; + e.max_y = row[17] ? strtof(row[17], nullptr) : 0; + e.max_z = row[18] ? strtof(row[18], nullptr) : 0; e.skill_list = row[19] ? row[19] : ""; e.spell_list = row[20] ? row[20] : ""; e.zones = row[21] ? row[21] : ""; e.zone_version = static_cast(atoi(row[22])); e.optional = static_cast(atoi(row[23])); - e.list_group = static_cast(strtoul(row[24], nullptr, 10)); + e.list_group = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -477,31 +476,31 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { TaskActivities e{}; - e.taskid = static_cast(strtoul(row[0], nullptr, 10)); - e.activityid = static_cast(strtoul(row[1], nullptr, 10)); + e.taskid = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.activityid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.req_activity_id = static_cast(atoi(row[2])); e.step = static_cast(atoi(row[3])); - e.activitytype = static_cast(strtoul(row[4], nullptr, 10)); + e.activitytype = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; e.target_name = row[5] ? row[5] : ""; - e.goalmethod = static_cast(strtoul(row[6], nullptr, 10)); + e.goalmethod = row[6] ? static_cast(strtoul(row[6], nullptr, 10)) : 0; e.goalcount = static_cast(atoi(row[7])); e.description_override = row[8] ? row[8] : ""; e.npc_match_list = row[9] ? row[9] : ""; e.item_id_list = row[10] ? row[10] : ""; e.item_list = row[11] ? row[11] : ""; e.dz_switch_id = static_cast(atoi(row[12])); - e.min_x = strtof(row[13], nullptr); - e.min_y = strtof(row[14], nullptr); - e.min_z = strtof(row[15], nullptr); - e.max_x = strtof(row[16], nullptr); - e.max_y = strtof(row[17], nullptr); - e.max_z = strtof(row[18], nullptr); + e.min_x = row[13] ? strtof(row[13], nullptr) : 0; + e.min_y = row[14] ? strtof(row[14], nullptr) : 0; + e.min_z = row[15] ? strtof(row[15], nullptr) : 0; + e.max_x = row[16] ? strtof(row[16], nullptr) : 0; + e.max_y = row[17] ? strtof(row[17], nullptr) : 0; + e.max_z = row[18] ? strtof(row[18], nullptr) : 0; e.skill_list = row[19] ? row[19] : ""; e.spell_list = row[20] ? row[20] : ""; e.zones = row[21] ? row[21] : ""; e.zone_version = static_cast(atoi(row[22])); e.optional = static_cast(atoi(row[23])); - e.list_group = static_cast(strtoul(row[24], nullptr, 10)); + e.list_group = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; all_entries.push_back(e); } diff --git a/common/repositories/base/base_tasks_repository.h b/common/repositories/base/base_tasks_repository.h index f565bdd71..847125020 100644 --- a/common/repositories/base/base_tasks_repository.h +++ b/common/repositories/base/base_tasks_repository.h @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseTasksRepository { public: struct Tasks { @@ -228,32 +227,32 @@ public: if (results.RowCount() == 1) { Tasks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.type = static_cast(atoi(row[1])); - e.duration = static_cast(strtoul(row[2], nullptr, 10)); + e.duration = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.duration_code = static_cast(atoi(row[3])); e.title = row[4] ? row[4] : ""; e.description = row[5] ? row[5] : ""; e.reward_text = row[6] ? row[6] : ""; e.reward_id_list = row[7] ? row[7] : ""; - e.cash_reward = static_cast(strtoul(row[8], nullptr, 10)); + e.cash_reward = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.exp_reward = static_cast(atoi(row[9])); - e.reward_method = static_cast(strtoul(row[10], nullptr, 10)); + e.reward_method = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.reward_points = static_cast(atoi(row[11])); e.reward_point_type = static_cast(atoi(row[12])); - e.min_level = static_cast(strtoul(row[13], nullptr, 10)); - e.max_level = static_cast(strtoul(row[14], nullptr, 10)); - e.level_spread = static_cast(strtoul(row[15], nullptr, 10)); - e.min_players = static_cast(strtoul(row[16], nullptr, 10)); - e.max_players = static_cast(strtoul(row[17], nullptr, 10)); - e.repeatable = static_cast(strtoul(row[18], nullptr, 10)); + e.min_level = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.max_level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level_spread = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.min_players = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.max_players = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.repeatable = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; e.faction_reward = static_cast(atoi(row[19])); e.completion_emote = row[20] ? row[20] : ""; - e.replay_timer_group = static_cast(strtoul(row[21], nullptr, 10)); - e.replay_timer_seconds = static_cast(strtoul(row[22], nullptr, 10)); - e.request_timer_group = static_cast(strtoul(row[23], nullptr, 10)); - e.request_timer_seconds = static_cast(strtoul(row[24], nullptr, 10)); - e.dz_template_id = static_cast(strtoul(row[25], nullptr, 10)); + e.replay_timer_group = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.replay_timer_seconds = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.request_timer_group = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.request_timer_seconds = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.dz_template_id = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; e.lock_activity_id = static_cast(atoi(row[26])); e.faction_amount = static_cast(atoi(row[27])); e.enabled = static_cast(atoi(row[28])); @@ -460,32 +459,32 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tasks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.type = static_cast(atoi(row[1])); - e.duration = static_cast(strtoul(row[2], nullptr, 10)); + e.duration = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.duration_code = static_cast(atoi(row[3])); e.title = row[4] ? row[4] : ""; e.description = row[5] ? row[5] : ""; e.reward_text = row[6] ? row[6] : ""; e.reward_id_list = row[7] ? row[7] : ""; - e.cash_reward = static_cast(strtoul(row[8], nullptr, 10)); + e.cash_reward = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.exp_reward = static_cast(atoi(row[9])); - e.reward_method = static_cast(strtoul(row[10], nullptr, 10)); + e.reward_method = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.reward_points = static_cast(atoi(row[11])); e.reward_point_type = static_cast(atoi(row[12])); - e.min_level = static_cast(strtoul(row[13], nullptr, 10)); - e.max_level = static_cast(strtoul(row[14], nullptr, 10)); - e.level_spread = static_cast(strtoul(row[15], nullptr, 10)); - e.min_players = static_cast(strtoul(row[16], nullptr, 10)); - e.max_players = static_cast(strtoul(row[17], nullptr, 10)); - e.repeatable = static_cast(strtoul(row[18], nullptr, 10)); + e.min_level = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.max_level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level_spread = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.min_players = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.max_players = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.repeatable = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; e.faction_reward = static_cast(atoi(row[19])); e.completion_emote = row[20] ? row[20] : ""; - e.replay_timer_group = static_cast(strtoul(row[21], nullptr, 10)); - e.replay_timer_seconds = static_cast(strtoul(row[22], nullptr, 10)); - e.request_timer_group = static_cast(strtoul(row[23], nullptr, 10)); - e.request_timer_seconds = static_cast(strtoul(row[24], nullptr, 10)); - e.dz_template_id = static_cast(strtoul(row[25], nullptr, 10)); + e.replay_timer_group = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.replay_timer_seconds = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.request_timer_group = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.request_timer_seconds = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.dz_template_id = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; e.lock_activity_id = static_cast(atoi(row[26])); e.faction_amount = static_cast(atoi(row[27])); e.enabled = static_cast(atoi(row[28])); @@ -513,32 +512,32 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tasks e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.type = static_cast(atoi(row[1])); - e.duration = static_cast(strtoul(row[2], nullptr, 10)); + e.duration = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.duration_code = static_cast(atoi(row[3])); e.title = row[4] ? row[4] : ""; e.description = row[5] ? row[5] : ""; e.reward_text = row[6] ? row[6] : ""; e.reward_id_list = row[7] ? row[7] : ""; - e.cash_reward = static_cast(strtoul(row[8], nullptr, 10)); + e.cash_reward = row[8] ? static_cast(strtoul(row[8], nullptr, 10)) : 0; e.exp_reward = static_cast(atoi(row[9])); - e.reward_method = static_cast(strtoul(row[10], nullptr, 10)); + e.reward_method = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; e.reward_points = static_cast(atoi(row[11])); e.reward_point_type = static_cast(atoi(row[12])); - e.min_level = static_cast(strtoul(row[13], nullptr, 10)); - e.max_level = static_cast(strtoul(row[14], nullptr, 10)); - e.level_spread = static_cast(strtoul(row[15], nullptr, 10)); - e.min_players = static_cast(strtoul(row[16], nullptr, 10)); - e.max_players = static_cast(strtoul(row[17], nullptr, 10)); - e.repeatable = static_cast(strtoul(row[18], nullptr, 10)); + e.min_level = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.max_level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.level_spread = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 0; + e.min_players = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; + e.max_players = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; + e.repeatable = row[18] ? static_cast(strtoul(row[18], nullptr, 10)) : 1; e.faction_reward = static_cast(atoi(row[19])); e.completion_emote = row[20] ? row[20] : ""; - e.replay_timer_group = static_cast(strtoul(row[21], nullptr, 10)); - e.replay_timer_seconds = static_cast(strtoul(row[22], nullptr, 10)); - e.request_timer_group = static_cast(strtoul(row[23], nullptr, 10)); - e.request_timer_seconds = static_cast(strtoul(row[24], nullptr, 10)); - e.dz_template_id = static_cast(strtoul(row[25], nullptr, 10)); + e.replay_timer_group = row[21] ? static_cast(strtoul(row[21], nullptr, 10)) : 0; + e.replay_timer_seconds = row[22] ? static_cast(strtoul(row[22], nullptr, 10)) : 0; + e.request_timer_group = row[23] ? static_cast(strtoul(row[23], nullptr, 10)) : 0; + e.request_timer_seconds = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.dz_template_id = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; e.lock_activity_id = static_cast(atoi(row[26])); e.faction_amount = static_cast(atoi(row[27])); e.enabled = static_cast(atoi(row[28])); diff --git a/common/repositories/base/base_tasksets_repository.h b/common/repositories/base/base_tasksets_repository.h index 396d5fdee..9aa96368b 100644 --- a/common/repositories/base/base_tasksets_repository.h +++ b/common/repositories/base/base_tasksets_repository.h @@ -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_TASKSETS_REPOSITORY_H @@ -108,8 +108,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), tasksets_id ) ); @@ -118,8 +119,8 @@ public: if (results.RowCount() == 1) { Tasksets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; return e; } @@ -242,8 +243,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tasksets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -268,8 +269,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tasksets e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.taskid = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.taskid = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -328,6 +329,64 @@ 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 Tasksets &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.taskid)); + + 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(std::to_string(e.taskid)); + + 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_TASKSETS_REPOSITORY_H diff --git a/common/repositories/base/base_timers_repository.h b/common/repositories/base/base_timers_repository.h index cfe951099..4883acf4e 100644 --- a/common/repositories/base/base_timers_repository.h +++ b/common/repositories/base/base_timers_repository.h @@ -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_TIMERS_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), timers_id ) ); @@ -131,9 +132,9 @@ public: Timers e{}; e.char_id = static_cast(atoi(row[0])); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.start = static_cast(strtoul(row[2], nullptr, 10)); - e.duration = static_cast(strtoul(row[3], nullptr, 10)); + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.start = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.duration = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.enable = static_cast(atoi(row[4])); return e; @@ -267,9 +268,9 @@ public: Timers e{}; e.char_id = static_cast(atoi(row[0])); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.start = static_cast(strtoul(row[2], nullptr, 10)); - e.duration = static_cast(strtoul(row[3], nullptr, 10)); + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.start = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.duration = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.enable = static_cast(atoi(row[4])); all_entries.push_back(e); @@ -296,9 +297,9 @@ public: Timers e{}; e.char_id = static_cast(atoi(row[0])); - e.type = static_cast(strtoul(row[1], nullptr, 10)); - e.start = static_cast(strtoul(row[2], nullptr, 10)); - e.duration = static_cast(strtoul(row[3], nullptr, 10)); + e.type = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.start = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.duration = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; e.enable = static_cast(atoi(row[4])); all_entries.push_back(e); @@ -358,6 +359,70 @@ 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 Timers &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.start)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.enable)); + + 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.char_id)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.start)); + v.push_back(std::to_string(e.duration)); + v.push_back(std::to_string(e.enable)); + + 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_TIMERS_REPOSITORY_H diff --git a/common/repositories/base/base_titles_repository.h b/common/repositories/base/base_titles_repository.h index 851f4729e..a939fdd73 100644 --- a/common/repositories/base/base_titles_repository.h +++ b/common/repositories/base/base_titles_repository.h @@ -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_TITLES_REPOSITORY_H @@ -156,8 +156,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), titles_id ) ); @@ -166,7 +167,7 @@ public: if (results.RowCount() == 1) { Titles e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.skill_id = static_cast(atoi(row[1])); e.min_skill_value = static_cast(atoi(row[2])); e.max_skill_value = static_cast(atoi(row[3])); @@ -337,7 +338,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Titles e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.skill_id = static_cast(atoi(row[1])); e.min_skill_value = static_cast(atoi(row[2])); e.max_skill_value = static_cast(atoi(row[3])); @@ -375,7 +376,7 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Titles e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.skill_id = static_cast(atoi(row[1])); e.min_skill_value = static_cast(atoi(row[2])); e.max_skill_value = static_cast(atoi(row[3])); @@ -447,6 +448,88 @@ 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 Titles &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.skill_id)); + v.push_back(std::to_string(e.min_skill_value)); + v.push_back(std::to_string(e.max_skill_value)); + v.push_back(std::to_string(e.min_aa_points)); + v.push_back(std::to_string(e.max_aa_points)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.item_id)); + v.push_back("'" + Strings::Escape(e.prefix) + "'"); + v.push_back("'" + Strings::Escape(e.suffix) + "'"); + v.push_back(std::to_string(e.title_set)); + + 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(std::to_string(e.skill_id)); + v.push_back(std::to_string(e.min_skill_value)); + v.push_back(std::to_string(e.max_skill_value)); + v.push_back(std::to_string(e.min_aa_points)); + v.push_back(std::to_string(e.max_aa_points)); + v.push_back(std::to_string(e.class_)); + v.push_back(std::to_string(e.gender)); + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.status)); + v.push_back(std::to_string(e.item_id)); + v.push_back("'" + Strings::Escape(e.prefix) + "'"); + v.push_back("'" + Strings::Escape(e.suffix) + "'"); + v.push_back(std::to_string(e.title_set)); + + 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_TITLES_REPOSITORY_H diff --git a/common/repositories/base/base_trader_repository.h b/common/repositories/base/base_trader_repository.h index a057b6bc6..c4293ed3f 100644 --- a/common/repositories/base/base_trader_repository.h +++ b/common/repositories/base/base_trader_repository.h @@ -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_TRADER_REPOSITORY_H @@ -124,8 +124,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), trader_id ) ); @@ -134,12 +135,12 @@ public: if (results.RowCount() == 1) { Trader e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.item_id = static_cast(strtoul(row[1], nullptr, 10)); - e.serialnumber = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.item_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.serialnumber = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[3])); - e.item_cost = static_cast(strtoul(row[4], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[5], nullptr, 10)); + e.item_cost = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.slot_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; return e; } @@ -274,12 +275,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Trader e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.item_id = static_cast(strtoul(row[1], nullptr, 10)); - e.serialnumber = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.item_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.serialnumber = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[3])); - e.item_cost = static_cast(strtoul(row[4], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[5], nullptr, 10)); + e.item_cost = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.slot_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -304,12 +305,12 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Trader e{}; - e.char_id = static_cast(strtoul(row[0], nullptr, 10)); - e.item_id = static_cast(strtoul(row[1], nullptr, 10)); - e.serialnumber = static_cast(strtoul(row[2], nullptr, 10)); + e.char_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.item_id = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.serialnumber = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.charges = static_cast(atoi(row[3])); - e.item_cost = static_cast(strtoul(row[4], nullptr, 10)); - e.slot_id = static_cast(strtoul(row[5], nullptr, 10)); + e.item_cost = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; + e.slot_id = row[5] ? static_cast(strtoul(row[5], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -368,6 +369,72 @@ 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 Trader &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.char_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.serialnumber)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.item_cost)); + v.push_back(std::to_string(e.slot_id)); + + 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.char_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.serialnumber)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.item_cost)); + v.push_back(std::to_string(e.slot_id)); + + 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_TRADER_REPOSITORY_H diff --git a/common/repositories/base/base_tradeskill_recipe_entries_repository.h b/common/repositories/base/base_tradeskill_recipe_entries_repository.h index 77a0f1942..763e0ce79 100644 --- a/common/repositories/base/base_tradeskill_recipe_entries_repository.h +++ b/common/repositories/base/base_tradeskill_recipe_entries_repository.h @@ -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_TRADESKILL_RECIPE_ENTRIES_REPOSITORY_H @@ -132,8 +132,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), tradeskill_recipe_entries_id ) ); @@ -387,6 +388,76 @@ 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 TradeskillRecipeEntries &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.recipe_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.successcount)); + v.push_back(std::to_string(e.failcount)); + v.push_back(std::to_string(e.componentcount)); + v.push_back(std::to_string(e.salvagecount)); + v.push_back(std::to_string(e.iscontainer)); + + 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(std::to_string(e.recipe_id)); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.successcount)); + v.push_back(std::to_string(e.failcount)); + v.push_back(std::to_string(e.componentcount)); + v.push_back(std::to_string(e.salvagecount)); + v.push_back(std::to_string(e.iscontainer)); + + 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_TRADESKILL_RECIPE_ENTRIES_REPOSITORY_H diff --git a/common/repositories/base/base_tradeskill_recipe_repository.h b/common/repositories/base/base_tradeskill_recipe_repository.h index 2abb76dc3..6bbbc0214 100644 --- a/common/repositories/base/base_tradeskill_recipe_repository.h +++ b/common/repositories/base/base_tradeskill_recipe_repository.h @@ -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_TRADESKILL_RECIPE_REPOSITORY_H @@ -28,6 +28,7 @@ public: int8_t replace_container; std::string notes; int8_t must_learn; + int32_t learned_by_item_id; int8_t quest; int8_t enabled; int8_t min_expansion; @@ -53,6 +54,7 @@ public: "replace_container", "notes", "must_learn", + "learned_by_item_id", "quest", "enabled", "min_expansion", @@ -74,6 +76,7 @@ public: "replace_container", "notes", "must_learn", + "learned_by_item_id", "quest", "enabled", "min_expansion", @@ -129,6 +132,7 @@ public: e.replace_container = 0; e.notes = ""; e.must_learn = 0; + e.learned_by_item_id = 0; e.quest = 0; e.enabled = 1; e.min_expansion = -1; @@ -160,8 +164,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), tradeskill_recipe_id ) ); @@ -179,12 +184,13 @@ public: e.replace_container = static_cast(atoi(row[6])); e.notes = row[7] ? row[7] : ""; e.must_learn = static_cast(atoi(row[8])); - e.quest = static_cast(atoi(row[9])); - e.enabled = static_cast(atoi(row[10])); - e.min_expansion = static_cast(atoi(row[11])); - e.max_expansion = static_cast(atoi(row[12])); - e.content_flags = row[13] ? row[13] : ""; - e.content_flags_disabled = row[14] ? row[14] : ""; + e.learned_by_item_id = static_cast(atoi(row[9])); + e.quest = static_cast(atoi(row[10])); + e.enabled = static_cast(atoi(row[11])); + e.min_expansion = static_cast(atoi(row[12])); + e.max_expansion = static_cast(atoi(row[13])); + e.content_flags = row[14] ? row[14] : ""; + e.content_flags_disabled = row[15] ? row[15] : ""; return e; } @@ -226,12 +232,13 @@ public: v.push_back(columns[6] + " = " + std::to_string(e.replace_container)); v.push_back(columns[7] + " = '" + Strings::Escape(e.notes) + "'"); v.push_back(columns[8] + " = " + std::to_string(e.must_learn)); - v.push_back(columns[9] + " = " + std::to_string(e.quest)); - v.push_back(columns[10] + " = " + std::to_string(e.enabled)); - v.push_back(columns[11] + " = " + std::to_string(e.min_expansion)); - v.push_back(columns[12] + " = " + std::to_string(e.max_expansion)); - v.push_back(columns[13] + " = '" + Strings::Escape(e.content_flags) + "'"); - v.push_back(columns[14] + " = '" + Strings::Escape(e.content_flags_disabled) + "'"); + v.push_back(columns[9] + " = " + std::to_string(e.learned_by_item_id)); + v.push_back(columns[10] + " = " + std::to_string(e.quest)); + v.push_back(columns[11] + " = " + std::to_string(e.enabled)); + v.push_back(columns[12] + " = " + std::to_string(e.min_expansion)); + v.push_back(columns[13] + " = " + std::to_string(e.max_expansion)); + v.push_back(columns[14] + " = '" + Strings::Escape(e.content_flags) + "'"); + v.push_back(columns[15] + " = '" + Strings::Escape(e.content_flags_disabled) + "'"); auto results = db.QueryDatabase( fmt::format( @@ -262,6 +269,7 @@ public: v.push_back(std::to_string(e.replace_container)); v.push_back("'" + Strings::Escape(e.notes) + "'"); v.push_back(std::to_string(e.must_learn)); + v.push_back(std::to_string(e.learned_by_item_id)); v.push_back(std::to_string(e.quest)); v.push_back(std::to_string(e.enabled)); v.push_back(std::to_string(e.min_expansion)); @@ -306,6 +314,7 @@ public: v.push_back(std::to_string(e.replace_container)); v.push_back("'" + Strings::Escape(e.notes) + "'"); v.push_back(std::to_string(e.must_learn)); + v.push_back(std::to_string(e.learned_by_item_id)); v.push_back(std::to_string(e.quest)); v.push_back(std::to_string(e.enabled)); v.push_back(std::to_string(e.min_expansion)); @@ -354,12 +363,13 @@ public: e.replace_container = static_cast(atoi(row[6])); e.notes = row[7] ? row[7] : ""; e.must_learn = static_cast(atoi(row[8])); - e.quest = static_cast(atoi(row[9])); - e.enabled = static_cast(atoi(row[10])); - e.min_expansion = static_cast(atoi(row[11])); - e.max_expansion = static_cast(atoi(row[12])); - e.content_flags = row[13] ? row[13] : ""; - e.content_flags_disabled = row[14] ? row[14] : ""; + e.learned_by_item_id = static_cast(atoi(row[9])); + e.quest = static_cast(atoi(row[10])); + e.enabled = static_cast(atoi(row[11])); + e.min_expansion = static_cast(atoi(row[12])); + e.max_expansion = static_cast(atoi(row[13])); + e.content_flags = row[14] ? row[14] : ""; + e.content_flags_disabled = row[15] ? row[15] : ""; all_entries.push_back(e); } @@ -393,12 +403,13 @@ public: e.replace_container = static_cast(atoi(row[6])); e.notes = row[7] ? row[7] : ""; e.must_learn = static_cast(atoi(row[8])); - e.quest = static_cast(atoi(row[9])); - e.enabled = static_cast(atoi(row[10])); - e.min_expansion = static_cast(atoi(row[11])); - e.max_expansion = static_cast(atoi(row[12])); - e.content_flags = row[13] ? row[13] : ""; - e.content_flags_disabled = row[14] ? row[14] : ""; + e.learned_by_item_id = static_cast(atoi(row[9])); + e.quest = static_cast(atoi(row[10])); + e.enabled = static_cast(atoi(row[11])); + e.min_expansion = static_cast(atoi(row[12])); + e.max_expansion = static_cast(atoi(row[13])); + e.content_flags = row[14] ? row[14] : ""; + e.content_flags_disabled = row[15] ? row[15] : ""; all_entries.push_back(e); } @@ -457,6 +468,92 @@ 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 TradeskillRecipe &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.tradeskill)); + v.push_back(std::to_string(e.skillneeded)); + v.push_back(std::to_string(e.trivial)); + v.push_back(std::to_string(e.nofail)); + v.push_back(std::to_string(e.replace_container)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + v.push_back(std::to_string(e.must_learn)); + v.push_back(std::to_string(e.learned_by_item_id)); + v.push_back(std::to_string(e.quest)); + v.push_back(std::to_string(e.enabled)); + 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) + "'"); + + 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.name) + "'"); + v.push_back(std::to_string(e.tradeskill)); + v.push_back(std::to_string(e.skillneeded)); + v.push_back(std::to_string(e.trivial)); + v.push_back(std::to_string(e.nofail)); + v.push_back(std::to_string(e.replace_container)); + v.push_back("'" + Strings::Escape(e.notes) + "'"); + v.push_back(std::to_string(e.must_learn)); + v.push_back(std::to_string(e.learned_by_item_id)); + v.push_back(std::to_string(e.quest)); + v.push_back(std::to_string(e.enabled)); + 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) + "'"); + + 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_TRADESKILL_RECIPE_REPOSITORY_H diff --git a/common/repositories/base/base_traps_repository.h b/common/repositories/base/base_traps_repository.h index b40ad30b8..48f1e6d95 100644 --- a/common/repositories/base/base_traps_repository.h +++ b/common/repositories/base/base_traps_repository.h @@ -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_TRAPS_REPOSITORY_H @@ -200,8 +200,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), traps_id ) ); @@ -212,21 +213,21 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; - e.version = static_cast(strtoul(row[2], nullptr, 10)); + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.x = static_cast(atoi(row[3])); e.y = static_cast(atoi(row[4])); e.z = static_cast(atoi(row[5])); e.chance = static_cast(atoi(row[6])); - e.maxzdiff = strtof(row[7], nullptr); - e.radius = strtof(row[8], nullptr); + e.maxzdiff = row[7] ? strtof(row[7], nullptr) : 0; + e.radius = row[8] ? strtof(row[8], nullptr) : 0; e.effect = static_cast(atoi(row[9])); e.effectvalue = static_cast(atoi(row[10])); e.effectvalue2 = static_cast(atoi(row[11])); e.message = row[12] ? row[12] : ""; e.skill = static_cast(atoi(row[13])); - e.level = static_cast(strtoul(row[14], nullptr, 10)); - e.respawn_time = static_cast(strtoul(row[15], nullptr, 10)); - e.respawn_var = static_cast(strtoul(row[16], nullptr, 10)); + e.level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.respawn_time = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 60; + e.respawn_var = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.triggered_number = static_cast(atoi(row[17])); e.group = static_cast(atoi(row[18])); e.despawn_when_triggered = static_cast(atoi(row[19])); @@ -427,21 +428,21 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; - e.version = static_cast(strtoul(row[2], nullptr, 10)); + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.x = static_cast(atoi(row[3])); e.y = static_cast(atoi(row[4])); e.z = static_cast(atoi(row[5])); e.chance = static_cast(atoi(row[6])); - e.maxzdiff = strtof(row[7], nullptr); - e.radius = strtof(row[8], nullptr); + e.maxzdiff = row[7] ? strtof(row[7], nullptr) : 0; + e.radius = row[8] ? strtof(row[8], nullptr) : 0; e.effect = static_cast(atoi(row[9])); e.effectvalue = static_cast(atoi(row[10])); e.effectvalue2 = static_cast(atoi(row[11])); e.message = row[12] ? row[12] : ""; e.skill = static_cast(atoi(row[13])); - e.level = static_cast(strtoul(row[14], nullptr, 10)); - e.respawn_time = static_cast(strtoul(row[15], nullptr, 10)); - e.respawn_var = static_cast(strtoul(row[16], nullptr, 10)); + e.level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.respawn_time = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 60; + e.respawn_var = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.triggered_number = static_cast(atoi(row[17])); e.group = static_cast(atoi(row[18])); e.despawn_when_triggered = static_cast(atoi(row[19])); @@ -476,21 +477,21 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; - e.version = static_cast(strtoul(row[2], nullptr, 10)); + e.version = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; e.x = static_cast(atoi(row[3])); e.y = static_cast(atoi(row[4])); e.z = static_cast(atoi(row[5])); e.chance = static_cast(atoi(row[6])); - e.maxzdiff = strtof(row[7], nullptr); - e.radius = strtof(row[8], nullptr); + e.maxzdiff = row[7] ? strtof(row[7], nullptr) : 0; + e.radius = row[8] ? strtof(row[8], nullptr) : 0; e.effect = static_cast(atoi(row[9])); e.effectvalue = static_cast(atoi(row[10])); e.effectvalue2 = static_cast(atoi(row[11])); e.message = row[12] ? row[12] : ""; e.skill = static_cast(atoi(row[13])); - e.level = static_cast(strtoul(row[14], nullptr, 10)); - e.respawn_time = static_cast(strtoul(row[15], nullptr, 10)); - e.respawn_var = static_cast(strtoul(row[16], nullptr, 10)); + e.level = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 1; + e.respawn_time = row[15] ? static_cast(strtoul(row[15], nullptr, 10)) : 60; + e.respawn_var = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 0; e.triggered_number = static_cast(atoi(row[17])); e.group = static_cast(atoi(row[18])); e.despawn_when_triggered = static_cast(atoi(row[19])); @@ -557,6 +558,110 @@ 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 Traps &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.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.maxzdiff)); + v.push_back(std::to_string(e.radius)); + v.push_back(std::to_string(e.effect)); + v.push_back(std::to_string(e.effectvalue)); + v.push_back(std::to_string(e.effectvalue2)); + v.push_back("'" + Strings::Escape(e.message) + "'"); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.respawn_time)); + v.push_back(std::to_string(e.respawn_var)); + v.push_back(std::to_string(e.triggered_number)); + v.push_back(std::to_string(e.group)); + v.push_back(std::to_string(e.despawn_when_triggered)); + v.push_back(std::to_string(e.undetectable)); + 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) + "'"); + + 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.x)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.chance)); + v.push_back(std::to_string(e.maxzdiff)); + v.push_back(std::to_string(e.radius)); + v.push_back(std::to_string(e.effect)); + v.push_back(std::to_string(e.effectvalue)); + v.push_back(std::to_string(e.effectvalue2)); + v.push_back("'" + Strings::Escape(e.message) + "'"); + v.push_back(std::to_string(e.skill)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.respawn_time)); + v.push_back(std::to_string(e.respawn_var)); + v.push_back(std::to_string(e.triggered_number)); + v.push_back(std::to_string(e.group)); + v.push_back(std::to_string(e.despawn_when_triggered)); + v.push_back(std::to_string(e.undetectable)); + 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) + "'"); + + 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_TRAPS_REPOSITORY_H diff --git a/common/repositories/base/base_tribute_levels_repository.h b/common/repositories/base/base_tribute_levels_repository.h index 52ab42899..28be3327f 100644 --- a/common/repositories/base/base_tribute_levels_repository.h +++ b/common/repositories/base/base_tribute_levels_repository.h @@ -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_TRIBUTE_LEVELS_REPOSITORY_H @@ -116,8 +116,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), tribute_levels_id ) ); @@ -126,10 +127,10 @@ public: if (results.RowCount() == 1) { TributeLevels e{}; - e.tribute_id = static_cast(strtoul(row[0], nullptr, 10)); - e.level = static_cast(strtoul(row[1], nullptr, 10)); - e.cost = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.tribute_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.level = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.cost = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; return e; } @@ -258,10 +259,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { TributeLevels e{}; - e.tribute_id = static_cast(strtoul(row[0], nullptr, 10)); - e.level = static_cast(strtoul(row[1], nullptr, 10)); - e.cost = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.tribute_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.level = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.cost = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -286,10 +287,10 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { TributeLevels e{}; - e.tribute_id = static_cast(strtoul(row[0], nullptr, 10)); - e.level = static_cast(strtoul(row[1], nullptr, 10)); - e.cost = static_cast(strtoul(row[2], nullptr, 10)); - e.item_id = static_cast(strtoul(row[3], nullptr, 10)); + e.tribute_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.level = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; + e.cost = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.item_id = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -348,6 +349,68 @@ 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 TributeLevels &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.tribute_id)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.cost)); + v.push_back(std::to_string(e.item_id)); + + 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.tribute_id)); + v.push_back(std::to_string(e.level)); + v.push_back(std::to_string(e.cost)); + v.push_back(std::to_string(e.item_id)); + + 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_TRIBUTE_LEVELS_REPOSITORY_H diff --git a/common/repositories/base/base_tributes_repository.h b/common/repositories/base/base_tributes_repository.h index 81d9e6489..688ee098e 100644 --- a/common/repositories/base/base_tributes_repository.h +++ b/common/repositories/base/base_tributes_repository.h @@ -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_TRIBUTES_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), tributes_id ) ); @@ -130,8 +131,8 @@ public: if (results.RowCount() == 1) { Tributes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.unknown = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.unknown = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.name = row[2] ? row[2] : ""; e.descr = row[3] ? row[3] : ""; e.isguild = static_cast(atoi(row[4])); @@ -266,8 +267,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tributes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.unknown = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.unknown = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.name = row[2] ? row[2] : ""; e.descr = row[3] ? row[3] : ""; e.isguild = static_cast(atoi(row[4])); @@ -295,8 +296,8 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { Tributes e{}; - e.id = static_cast(strtoul(row[0], nullptr, 10)); - e.unknown = static_cast(strtoul(row[1], nullptr, 10)); + e.id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; + e.unknown = row[1] ? static_cast(strtoul(row[1], nullptr, 10)) : 0; e.name = row[2] ? row[2] : ""; e.descr = row[3] ? row[3] : ""; e.isguild = static_cast(atoi(row[4])); @@ -358,6 +359,70 @@ 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 Tributes &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back(std::to_string(e.unknown)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.descr) + "'"); + v.push_back(std::to_string(e.isguild)); + + 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(std::to_string(e.unknown)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back("'" + Strings::Escape(e.descr) + "'"); + v.push_back(std::to_string(e.isguild)); + + 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_TRIBUTES_REPOSITORY_H diff --git a/common/repositories/base/base_variables_repository.h b/common/repositories/base/base_variables_repository.h index 09facf31e..dc959269c 100644 --- a/common/repositories/base/base_variables_repository.h +++ b/common/repositories/base/base_variables_repository.h @@ -1,8 +1,12 @@ /** + * 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 + * 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_VARIABLES_REPOSITORY_H @@ -10,10 +14,12 @@ #include "../../database.h" #include "../../strings.h" +#include class BaseVariablesRepository { public: struct Variables { + int32_t id; std::string varname; std::string value; std::string information; @@ -22,12 +28,24 @@ public: static std::string PrimaryKey() { - return std::string("varname"); + return std::string("id"); } static std::vector Columns() { return { + "id", + "varname", + "value", + "information", + "ts", + }; + } + + static std::vector SelectColumns() + { + return { + "id", "varname", "value", "information", @@ -40,19 +58,9 @@ public: return std::string(Strings::Implode(", ", Columns())); } - static std::string InsertColumnsRaw() + static std::string SelectColumnsRaw() { - std::vector insert_columns; - - for (auto &column : Columns()) { - if (column == PrimaryKey()) { - continue; - } - - insert_columns.push_back(column); - } - - return std::string(Strings::Implode(", ", insert_columns)); + return std::string(Strings::Implode(", ", SelectColumns())); } static std::string TableName() @@ -64,7 +72,7 @@ public: { return fmt::format( "SELECT {} FROM {}", - ColumnsRaw(), + SelectColumnsRaw(), TableName() ); } @@ -74,29 +82,30 @@ public: return fmt::format( "INSERT INTO {} ({}) ", TableName(), - InsertColumnsRaw() + ColumnsRaw() ); } static Variables NewEntity() { - Variables entry{}; + Variables e{}; - entry.varname = ""; - entry.value = ""; - entry.information = ""; - entry.ts = current_timestamp(); + e.id = 0; + e.varname = ""; + e.value = ""; + e.information = ""; + e.ts = std::time(nullptr); - return entry; + return e; } - static Variables GetVariablesEntry( + static Variables GetVariables( const std::vector &variabless, int variables_id ) { for (auto &variables : variabless) { - if (variables.varname == variables_id) { + if (variables.id == variables_id) { return variables; } } @@ -105,37 +114,41 @@ public: } static Variables FindOne( + Database& db, int variables_id ) { - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), variables_id ) ); auto row = results.begin(); if (results.RowCount() == 1) { - Variables entry{}; + Variables e{}; - entry.varname = row[0] ? row[0] : ""; - entry.value = row[1] ? row[1] : ""; - entry.information = row[2] ? row[2] : ""; - entry.ts = row[3] ? row[3] : ""; + e.id = static_cast(atoi(row[0])); + e.varname = row[1] ? row[1] : ""; + e.value = row[2] ? row[2] : ""; + e.information = row[3] ? row[3] : ""; + e.ts = row[4] ? row[4] : ""; - return entry; + return e; } return NewEntity(); } static int DeleteOne( + Database& db, int variables_id ) { - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "DELETE FROM {} WHERE {} = {}", TableName(), @@ -148,25 +161,26 @@ public: } static int UpdateOne( - Variables variables_entry + Database& db, + const Variables &e ) { - std::vector update_values; + std::vector v; auto columns = Columns(); - update_values.push_back(columns[0] + " = '" + Strings::Escape(variables_entry.varname) + "'"); - update_values.push_back(columns[1] + " = '" + Strings::Escape(variables_entry.value) + "'"); - update_values.push_back(columns[2] + " = '" + Strings::Escape(variables_entry.information) + "'"); - update_values.push_back(columns[3] + " = '" + Strings::Escape(variables_entry.ts) + "'"); + v.push_back(columns[1] + " = '" + Strings::Escape(e.varname) + "'"); + v.push_back(columns[2] + " = '" + Strings::Escape(e.value) + "'"); + v.push_back(columns[3] + " = '" + Strings::Escape(e.information) + "'"); + v.push_back(columns[4] + " = '" + Strings::Escape(e.ts) + "'"); - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "UPDATE {} SET {} WHERE {} = {}", TableName(), - Strings::Implode(", ", update_values), + Strings::Implode(", ", v), PrimaryKey(), - variables_entry.varname + e.id ) ); @@ -174,54 +188,58 @@ public: } static Variables InsertOne( - Variables variables_entry + Database& db, + Variables e ) { - std::vector insert_values; + std::vector v; - insert_values.push_back("'" + Strings::Escape(variables_entry.varname) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.value) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.information) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.ts) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.varname) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back("'" + Strings::Escape(e.information) + "'"); + v.push_back("'" + Strings::Escape(e.ts) + "'"); - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "{} VALUES ({})", BaseInsert(), - Strings::Implode(",", insert_values) + Strings::Implode(",", v) ) ); if (results.Success()) { - variables_entry.varname = results.LastInsertedID(); - return variables_entry; + e.id = results.LastInsertedID(); + return e; } - variables_entry = NewEntity(); + e = NewEntity(); - return variables_entry; + return e; } static int InsertMany( - std::vector variables_entries + Database& db, + const std::vector &entries ) { std::vector insert_chunks; - for (auto &variables_entry: variables_entries) { - std::vector insert_values; + for (auto &e: entries) { + std::vector v; - insert_values.push_back("'" + Strings::Escape(variables_entry.varname) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.value) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.information) + "'"); - insert_values.push_back("'" + Strings::Escape(variables_entry.ts) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.varname) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back("'" + Strings::Escape(e.information) + "'"); + v.push_back("'" + Strings::Escape(e.ts) + "'"); - insert_chunks.push_back("(" + Strings::Implode(",", insert_values) + ")"); + insert_chunks.push_back("(" + Strings::Implode(",", v) + ")"); } - std::vector insert_values; + std::vector v; - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "{} VALUES {}", BaseInsert(), @@ -232,11 +250,11 @@ public: return (results.Success() ? results.RowsAffected() : 0); } - static std::vector All() + static std::vector All(Database& db) { std::vector all_entries; - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "{}", BaseSelect() @@ -246,24 +264,25 @@ public: all_entries.reserve(results.RowCount()); for (auto row = results.begin(); row != results.end(); ++row) { - Variables entry{}; + Variables e{}; - entry.varname = row[0] ? row[0] : ""; - entry.value = row[1] ? row[1] : ""; - entry.information = row[2] ? row[2] : ""; - entry.ts = row[3] ? row[3] : ""; + e.id = static_cast(atoi(row[0])); + e.varname = row[1] ? row[1] : ""; + e.value = row[2] ? row[2] : ""; + e.information = row[3] ? row[3] : ""; + e.ts = row[4] ? row[4] : ""; - all_entries.push_back(entry); + all_entries.push_back(e); } return all_entries; } - static std::vector GetWhere(std::string where_filter) + static std::vector GetWhere(Database& db, const std::string &where_filter) { std::vector all_entries; - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "{} WHERE {}", BaseSelect(), @@ -274,26 +293,26 @@ public: all_entries.reserve(results.RowCount()); for (auto row = results.begin(); row != results.end(); ++row) { - Variables entry{}; + Variables e{}; - entry.varname = row[0] ? row[0] : ""; - entry.value = row[1] ? row[1] : ""; - entry.information = row[2] ? row[2] : ""; - entry.ts = row[3] ? row[3] : ""; + e.id = static_cast(atoi(row[0])); + e.varname = row[1] ? row[1] : ""; + e.value = row[2] ? row[2] : ""; + e.information = row[3] ? row[3] : ""; + e.ts = row[4] ? row[4] : ""; - all_entries.push_back(entry); + all_entries.push_back(e); } return all_entries; } - static int DeleteWhere(std::string where_filter) + static int DeleteWhere(Database& db, const std::string &where_filter) { - auto results = database.QueryDatabase( + auto results = db.QueryDatabase( fmt::format( "DELETE FROM {} WHERE {}", TableName(), - PrimaryKey(), where_filter ) ); @@ -301,6 +320,108 @@ public: 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 Variables &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.varname) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back("'" + Strings::Escape(e.information) + "'"); + v.push_back("'" + Strings::Escape(e.ts) + "'"); + + 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.varname) + "'"); + v.push_back("'" + Strings::Escape(e.value) + "'"); + v.push_back("'" + Strings::Escape(e.information) + "'"); + v.push_back("'" + Strings::Escape(e.ts) + "'"); + + 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_VARIABLES_REPOSITORY_H diff --git a/common/repositories/base/base_veteran_reward_templates_repository.h b/common/repositories/base/base_veteran_reward_templates_repository.h index c3233a3d5..fc5f52a0d 100644 --- a/common/repositories/base/base_veteran_reward_templates_repository.h +++ b/common/repositories/base/base_veteran_reward_templates_repository.h @@ -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_VETERAN_REWARD_TEMPLATES_REPOSITORY_H @@ -120,8 +120,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), veteran_reward_templates_id ) ); @@ -130,11 +131,11 @@ public: if (results.RowCount() == 1) { VeteranRewardTemplates e{}; - e.claim_id = static_cast(strtoul(row[0], nullptr, 10)); + e.claim_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.reward_slot = static_cast(strtoul(row[4], nullptr, 10)); + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.reward_slot = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; return e; } @@ -266,11 +267,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { VeteranRewardTemplates e{}; - e.claim_id = static_cast(strtoul(row[0], nullptr, 10)); + e.claim_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.reward_slot = static_cast(strtoul(row[4], nullptr, 10)); + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.reward_slot = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -295,11 +296,11 @@ public: for (auto row = results.begin(); row != results.end(); ++row) { VeteranRewardTemplates e{}; - e.claim_id = static_cast(strtoul(row[0], nullptr, 10)); + e.claim_id = row[0] ? static_cast(strtoul(row[0], nullptr, 10)) : 0; e.name = row[1] ? row[1] : ""; - e.item_id = static_cast(strtoul(row[2], nullptr, 10)); - e.charges = static_cast(strtoul(row[3], nullptr, 10)); - e.reward_slot = static_cast(strtoul(row[4], nullptr, 10)); + e.item_id = row[2] ? static_cast(strtoul(row[2], nullptr, 10)) : 0; + e.charges = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 0; + e.reward_slot = row[4] ? static_cast(strtoul(row[4], nullptr, 10)) : 0; all_entries.push_back(e); } @@ -358,6 +359,70 @@ 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 VeteranRewardTemplates &e + ) + { + std::vector v; + + v.push_back(std::to_string(e.claim_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.reward_slot)); + + 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.claim_id)); + v.push_back("'" + Strings::Escape(e.name) + "'"); + v.push_back(std::to_string(e.item_id)); + v.push_back(std::to_string(e.charges)); + v.push_back(std::to_string(e.reward_slot)); + + 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_VETERAN_REWARD_TEMPLATES_REPOSITORY_H diff --git a/common/repositories/base/base_zone_points_repository.h b/common/repositories/base/base_zone_points_repository.h index 286159d0c..e7bfbcdc0 100644 --- a/common/repositories/base/base_zone_points_repository.h +++ b/common/repositories/base/base_zone_points_repository.h @@ -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_ZONE_POINTS_REPOSITORY_H @@ -196,8 +196,9 @@ public: { auto results = db.QueryDatabase( fmt::format( - "{} WHERE id = {} LIMIT 1", + "{} WHERE {} = {} LIMIT 1", BaseSelect(), + PrimaryKey(), zone_points_id ) ); @@ -209,20 +210,20 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; e.version = static_cast(atoi(row[2])); - e.number = static_cast(strtoul(row[3], nullptr, 10)); - e.y = strtof(row[4], nullptr); - e.x = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); - e.target_y = strtof(row[8], nullptr); - e.target_x = strtof(row[9], nullptr); - e.target_z = strtof(row[10], nullptr); - e.target_heading = strtof(row[11], nullptr); - e.zoneinst = static_cast(strtoul(row[12], nullptr, 10)); - e.target_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.target_instance = static_cast(strtoul(row[14], nullptr, 10)); - e.buffer = strtof(row[15], nullptr); - e.client_version_mask = static_cast(strtoul(row[16], nullptr, 10)); + e.number = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 1; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; + e.target_y = row[8] ? strtof(row[8], nullptr) : 0; + e.target_x = row[9] ? strtof(row[9], nullptr) : 0; + e.target_z = row[10] ? strtof(row[10], nullptr) : 0; + e.target_heading = row[11] ? strtof(row[11], nullptr) : 0; + e.zoneinst = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.target_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.target_instance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.buffer = row[15] ? strtof(row[15], nullptr) : 0; + e.client_version_mask = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 4294967295; e.min_expansion = static_cast(atoi(row[17])); e.max_expansion = static_cast(atoi(row[18])); e.content_flags = row[19] ? row[19] : ""; @@ -420,20 +421,20 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; e.version = static_cast(atoi(row[2])); - e.number = static_cast(strtoul(row[3], nullptr, 10)); - e.y = strtof(row[4], nullptr); - e.x = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); - e.target_y = strtof(row[8], nullptr); - e.target_x = strtof(row[9], nullptr); - e.target_z = strtof(row[10], nullptr); - e.target_heading = strtof(row[11], nullptr); - e.zoneinst = static_cast(strtoul(row[12], nullptr, 10)); - e.target_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.target_instance = static_cast(strtoul(row[14], nullptr, 10)); - e.buffer = strtof(row[15], nullptr); - e.client_version_mask = static_cast(strtoul(row[16], nullptr, 10)); + e.number = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 1; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; + e.target_y = row[8] ? strtof(row[8], nullptr) : 0; + e.target_x = row[9] ? strtof(row[9], nullptr) : 0; + e.target_z = row[10] ? strtof(row[10], nullptr) : 0; + e.target_heading = row[11] ? strtof(row[11], nullptr) : 0; + e.zoneinst = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.target_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.target_instance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.buffer = row[15] ? strtof(row[15], nullptr) : 0; + e.client_version_mask = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 4294967295; e.min_expansion = static_cast(atoi(row[17])); e.max_expansion = static_cast(atoi(row[18])); e.content_flags = row[19] ? row[19] : ""; @@ -468,20 +469,20 @@ public: e.id = static_cast(atoi(row[0])); e.zone = row[1] ? row[1] : ""; e.version = static_cast(atoi(row[2])); - e.number = static_cast(strtoul(row[3], nullptr, 10)); - e.y = strtof(row[4], nullptr); - e.x = strtof(row[5], nullptr); - e.z = strtof(row[6], nullptr); - e.heading = strtof(row[7], nullptr); - e.target_y = strtof(row[8], nullptr); - e.target_x = strtof(row[9], nullptr); - e.target_z = strtof(row[10], nullptr); - e.target_heading = strtof(row[11], nullptr); - e.zoneinst = static_cast(strtoul(row[12], nullptr, 10)); - e.target_zone_id = static_cast(strtoul(row[13], nullptr, 10)); - e.target_instance = static_cast(strtoul(row[14], nullptr, 10)); - e.buffer = strtof(row[15], nullptr); - e.client_version_mask = static_cast(strtoul(row[16], nullptr, 10)); + e.number = row[3] ? static_cast(strtoul(row[3], nullptr, 10)) : 1; + e.y = row[4] ? strtof(row[4], nullptr) : 0; + e.x = row[5] ? strtof(row[5], nullptr) : 0; + e.z = row[6] ? strtof(row[6], nullptr) : 0; + e.heading = row[7] ? strtof(row[7], nullptr) : 0; + e.target_y = row[8] ? strtof(row[8], nullptr) : 0; + e.target_x = row[9] ? strtof(row[9], nullptr) : 0; + e.target_z = row[10] ? strtof(row[10], nullptr) : 0; + e.target_heading = row[11] ? strtof(row[11], nullptr) : 0; + e.zoneinst = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; + e.target_zone_id = row[13] ? static_cast(strtoul(row[13], nullptr, 10)) : 0; + e.target_instance = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; + e.buffer = row[15] ? strtof(row[15], nullptr) : 0; + e.client_version_mask = row[16] ? static_cast(strtoul(row[16], nullptr, 10)) : 4294967295; e.min_expansion = static_cast(atoi(row[17])); e.max_expansion = static_cast(atoi(row[18])); e.content_flags = row[19] ? row[19] : ""; @@ -547,6 +548,108 @@ public: return (results.Success() && results.begin()[0] ? strtoll(results.begin()[0], nullptr, 10) : 0); } + static std::string BaseReplace() + { + return fmt::format( + "REPLACE INTO {} ({}) ", + TableName(), + ColumnsRaw() + ); + } + + static int ReplaceOne( + Database& db, + const ZonePoints &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.number)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.target_y)); + v.push_back(std::to_string(e.target_x)); + v.push_back(std::to_string(e.target_z)); + v.push_back(std::to_string(e.target_heading)); + v.push_back(std::to_string(e.zoneinst)); + v.push_back(std::to_string(e.target_zone_id)); + v.push_back(std::to_string(e.target_instance)); + v.push_back(std::to_string(e.buffer)); + v.push_back(std::to_string(e.client_version_mask)); + 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.is_virtual)); + v.push_back(std::to_string(e.height)); + v.push_back(std::to_string(e.width)); + + 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.number)); + v.push_back(std::to_string(e.y)); + v.push_back(std::to_string(e.x)); + v.push_back(std::to_string(e.z)); + v.push_back(std::to_string(e.heading)); + v.push_back(std::to_string(e.target_y)); + v.push_back(std::to_string(e.target_x)); + v.push_back(std::to_string(e.target_z)); + v.push_back(std::to_string(e.target_heading)); + v.push_back(std::to_string(e.zoneinst)); + v.push_back(std::to_string(e.target_zone_id)); + v.push_back(std::to_string(e.target_instance)); + v.push_back(std::to_string(e.buffer)); + v.push_back(std::to_string(e.client_version_mask)); + 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.is_virtual)); + v.push_back(std::to_string(e.height)); + v.push_back(std::to_string(e.width)); + + 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_ZONE_POINTS_REPOSITORY_H diff --git a/common/repositories/base/base_zone_repository.h b/common/repositories/base/base_zone_repository.h index 90f07fc86..3e875169d 100644 --- a/common/repositories/base/base_zone_repository.h +++ b/common/repositories/base/base_zone_repository.h @@ -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_ZONE_REPOSITORY_H @@ -16,7 +16,6 @@ #include "../../strings.h" #include - class BaseZoneRepository { public: struct Zone { @@ -501,66 +500,66 @@ public: e.file_name = row[2] ? row[2] : ""; e.long_name = row[3] ? row[3] : ""; e.map_file_name = row[4] ? row[4] : ""; - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); - e.graveyard_id = strtof(row[9], nullptr); - e.min_level = static_cast(strtoul(row[10], nullptr, 10)); - e.max_level = static_cast(strtoul(row[11], nullptr, 10)); - e.min_status = static_cast(strtoul(row[12], nullptr, 10)); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; + e.graveyard_id = row[9] ? strtof(row[9], nullptr) : 0; + e.min_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_level = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 255; + e.min_status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.zoneidnumber = static_cast(atoi(row[13])); - e.version = static_cast(strtoul(row[14], nullptr, 10)); + e.version = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.timezone = static_cast(atoi(row[15])); e.maxclients = static_cast(atoi(row[16])); - e.ruleset = static_cast(strtoul(row[17], nullptr, 10)); + e.ruleset = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.note = row[18] ? row[18] : ""; - e.underworld = strtof(row[19], nullptr); - e.minclip = strtof(row[20], nullptr); - e.maxclip = strtof(row[21], nullptr); - e.fog_minclip = strtof(row[22], nullptr); - e.fog_maxclip = strtof(row[23], nullptr); - e.fog_blue = static_cast(strtoul(row[24], nullptr, 10)); - e.fog_red = static_cast(strtoul(row[25], nullptr, 10)); - e.fog_green = static_cast(strtoul(row[26], nullptr, 10)); - e.sky = static_cast(strtoul(row[27], nullptr, 10)); - e.ztype = static_cast(strtoul(row[28], nullptr, 10)); - e.zone_exp_multiplier = strtof(row[29], nullptr); - e.walkspeed = strtof(row[30], nullptr); - e.time_type = static_cast(strtoul(row[31], nullptr, 10)); - e.fog_red1 = static_cast(strtoul(row[32], nullptr, 10)); - e.fog_green1 = static_cast(strtoul(row[33], nullptr, 10)); - e.fog_blue1 = static_cast(strtoul(row[34], nullptr, 10)); - e.fog_minclip1 = strtof(row[35], nullptr); - e.fog_maxclip1 = strtof(row[36], nullptr); - e.fog_red2 = static_cast(strtoul(row[37], nullptr, 10)); - e.fog_green2 = static_cast(strtoul(row[38], nullptr, 10)); - e.fog_blue2 = static_cast(strtoul(row[39], nullptr, 10)); - e.fog_minclip2 = strtof(row[40], nullptr); - e.fog_maxclip2 = strtof(row[41], nullptr); - e.fog_red3 = static_cast(strtoul(row[42], nullptr, 10)); - e.fog_green3 = static_cast(strtoul(row[43], nullptr, 10)); - e.fog_blue3 = static_cast(strtoul(row[44], nullptr, 10)); - e.fog_minclip3 = strtof(row[45], nullptr); - e.fog_maxclip3 = strtof(row[46], nullptr); - e.fog_red4 = static_cast(strtoul(row[47], nullptr, 10)); - e.fog_green4 = static_cast(strtoul(row[48], nullptr, 10)); - e.fog_blue4 = static_cast(strtoul(row[49], nullptr, 10)); - e.fog_minclip4 = strtof(row[50], nullptr); - e.fog_maxclip4 = strtof(row[51], nullptr); - e.fog_density = strtof(row[52], nullptr); + e.underworld = row[19] ? strtof(row[19], nullptr) : 0; + e.minclip = row[20] ? strtof(row[20], nullptr) : 450; + e.maxclip = row[21] ? strtof(row[21], nullptr) : 450; + e.fog_minclip = row[22] ? strtof(row[22], nullptr) : 450; + e.fog_maxclip = row[23] ? strtof(row[23], nullptr) : 450; + e.fog_blue = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.fog_red = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.fog_green = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.sky = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 1; + e.ztype = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 1; + e.zone_exp_multiplier = row[29] ? strtof(row[29], nullptr) : 0.00; + e.walkspeed = row[30] ? strtof(row[30], nullptr) : 0.4; + e.time_type = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 2; + e.fog_red1 = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.fog_green1 = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.fog_blue1 = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.fog_minclip1 = row[35] ? strtof(row[35], nullptr) : 450; + e.fog_maxclip1 = row[36] ? strtof(row[36], nullptr) : 450; + e.fog_red2 = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.fog_green2 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.fog_blue2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.fog_minclip2 = row[40] ? strtof(row[40], nullptr) : 450; + e.fog_maxclip2 = row[41] ? strtof(row[41], nullptr) : 450; + e.fog_red3 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.fog_green3 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.fog_blue3 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.fog_minclip3 = row[45] ? strtof(row[45], nullptr) : 450; + e.fog_maxclip3 = row[46] ? strtof(row[46], nullptr) : 450; + e.fog_red4 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.fog_green4 = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.fog_blue4 = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.fog_minclip4 = row[50] ? strtof(row[50], nullptr) : 450; + e.fog_maxclip4 = row[51] ? strtof(row[51], nullptr) : 450; + e.fog_density = row[52] ? strtof(row[52], nullptr) : 0; e.flag_needed = row[53] ? row[53] : ""; e.canbind = static_cast(atoi(row[54])); e.cancombat = static_cast(atoi(row[55])); e.canlevitate = static_cast(atoi(row[56])); e.castoutdoor = static_cast(atoi(row[57])); - e.hotzone = static_cast(strtoul(row[58], nullptr, 10)); - e.insttype = static_cast(strtoul(row[59], nullptr, 10)); - e.shutdowndelay = strtoull(row[60], nullptr, 10); + e.hotzone = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.insttype = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.shutdowndelay = row[60] ? strtoull(row[60], nullptr, 10) : 5000; e.peqzone = static_cast(atoi(row[61])); e.expansion = static_cast(atoi(row[62])); e.bypass_expansion_check = static_cast(atoi(row[63])); - e.suspendbuffs = static_cast(strtoul(row[64], nullptr, 10)); + e.suspendbuffs = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; e.rain_chance1 = static_cast(atoi(row[65])); e.rain_chance2 = static_cast(atoi(row[66])); e.rain_chance3 = static_cast(atoi(row[67])); @@ -577,14 +576,14 @@ public: e.snow_duration2 = static_cast(atoi(row[78])); e.snow_duration3 = static_cast(atoi(row[79])); e.snow_duration4 = static_cast(atoi(row[80])); - e.gravity = strtof(row[81], nullptr); + e.gravity = row[81] ? strtof(row[81], nullptr) : 0.4; e.type = static_cast(atoi(row[82])); e.skylock = static_cast(atoi(row[83])); e.fast_regen_hp = static_cast(atoi(row[84])); e.fast_regen_mana = static_cast(atoi(row[85])); e.fast_regen_endurance = static_cast(atoi(row[86])); e.npc_max_aggro_dist = static_cast(atoi(row[87])); - e.max_movement_update_range = static_cast(strtoul(row[88], nullptr, 10)); + e.max_movement_update_range = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 600; e.min_expansion = static_cast(atoi(row[89])); e.max_expansion = static_cast(atoi(row[90])); e.content_flags = row[91] ? row[91] : ""; @@ -1000,66 +999,66 @@ public: e.file_name = row[2] ? row[2] : ""; e.long_name = row[3] ? row[3] : ""; e.map_file_name = row[4] ? row[4] : ""; - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); - e.graveyard_id = strtof(row[9], nullptr); - e.min_level = static_cast(strtoul(row[10], nullptr, 10)); - e.max_level = static_cast(strtoul(row[11], nullptr, 10)); - e.min_status = static_cast(strtoul(row[12], nullptr, 10)); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; + e.graveyard_id = row[9] ? strtof(row[9], nullptr) : 0; + e.min_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_level = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 255; + e.min_status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.zoneidnumber = static_cast(atoi(row[13])); - e.version = static_cast(strtoul(row[14], nullptr, 10)); + e.version = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.timezone = static_cast(atoi(row[15])); e.maxclients = static_cast(atoi(row[16])); - e.ruleset = static_cast(strtoul(row[17], nullptr, 10)); + e.ruleset = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.note = row[18] ? row[18] : ""; - e.underworld = strtof(row[19], nullptr); - e.minclip = strtof(row[20], nullptr); - e.maxclip = strtof(row[21], nullptr); - e.fog_minclip = strtof(row[22], nullptr); - e.fog_maxclip = strtof(row[23], nullptr); - e.fog_blue = static_cast(strtoul(row[24], nullptr, 10)); - e.fog_red = static_cast(strtoul(row[25], nullptr, 10)); - e.fog_green = static_cast(strtoul(row[26], nullptr, 10)); - e.sky = static_cast(strtoul(row[27], nullptr, 10)); - e.ztype = static_cast(strtoul(row[28], nullptr, 10)); - e.zone_exp_multiplier = strtof(row[29], nullptr); - e.walkspeed = strtof(row[30], nullptr); - e.time_type = static_cast(strtoul(row[31], nullptr, 10)); - e.fog_red1 = static_cast(strtoul(row[32], nullptr, 10)); - e.fog_green1 = static_cast(strtoul(row[33], nullptr, 10)); - e.fog_blue1 = static_cast(strtoul(row[34], nullptr, 10)); - e.fog_minclip1 = strtof(row[35], nullptr); - e.fog_maxclip1 = strtof(row[36], nullptr); - e.fog_red2 = static_cast(strtoul(row[37], nullptr, 10)); - e.fog_green2 = static_cast(strtoul(row[38], nullptr, 10)); - e.fog_blue2 = static_cast(strtoul(row[39], nullptr, 10)); - e.fog_minclip2 = strtof(row[40], nullptr); - e.fog_maxclip2 = strtof(row[41], nullptr); - e.fog_red3 = static_cast(strtoul(row[42], nullptr, 10)); - e.fog_green3 = static_cast(strtoul(row[43], nullptr, 10)); - e.fog_blue3 = static_cast(strtoul(row[44], nullptr, 10)); - e.fog_minclip3 = strtof(row[45], nullptr); - e.fog_maxclip3 = strtof(row[46], nullptr); - e.fog_red4 = static_cast(strtoul(row[47], nullptr, 10)); - e.fog_green4 = static_cast(strtoul(row[48], nullptr, 10)); - e.fog_blue4 = static_cast(strtoul(row[49], nullptr, 10)); - e.fog_minclip4 = strtof(row[50], nullptr); - e.fog_maxclip4 = strtof(row[51], nullptr); - e.fog_density = strtof(row[52], nullptr); + e.underworld = row[19] ? strtof(row[19], nullptr) : 0; + e.minclip = row[20] ? strtof(row[20], nullptr) : 450; + e.maxclip = row[21] ? strtof(row[21], nullptr) : 450; + e.fog_minclip = row[22] ? strtof(row[22], nullptr) : 450; + e.fog_maxclip = row[23] ? strtof(row[23], nullptr) : 450; + e.fog_blue = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.fog_red = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.fog_green = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.sky = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 1; + e.ztype = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 1; + e.zone_exp_multiplier = row[29] ? strtof(row[29], nullptr) : 0.00; + e.walkspeed = row[30] ? strtof(row[30], nullptr) : 0.4; + e.time_type = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 2; + e.fog_red1 = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.fog_green1 = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.fog_blue1 = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.fog_minclip1 = row[35] ? strtof(row[35], nullptr) : 450; + e.fog_maxclip1 = row[36] ? strtof(row[36], nullptr) : 450; + e.fog_red2 = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.fog_green2 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.fog_blue2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.fog_minclip2 = row[40] ? strtof(row[40], nullptr) : 450; + e.fog_maxclip2 = row[41] ? strtof(row[41], nullptr) : 450; + e.fog_red3 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.fog_green3 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.fog_blue3 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.fog_minclip3 = row[45] ? strtof(row[45], nullptr) : 450; + e.fog_maxclip3 = row[46] ? strtof(row[46], nullptr) : 450; + e.fog_red4 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.fog_green4 = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.fog_blue4 = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.fog_minclip4 = row[50] ? strtof(row[50], nullptr) : 450; + e.fog_maxclip4 = row[51] ? strtof(row[51], nullptr) : 450; + e.fog_density = row[52] ? strtof(row[52], nullptr) : 0; e.flag_needed = row[53] ? row[53] : ""; e.canbind = static_cast(atoi(row[54])); e.cancombat = static_cast(atoi(row[55])); e.canlevitate = static_cast(atoi(row[56])); e.castoutdoor = static_cast(atoi(row[57])); - e.hotzone = static_cast(strtoul(row[58], nullptr, 10)); - e.insttype = static_cast(strtoul(row[59], nullptr, 10)); - e.shutdowndelay = strtoull(row[60], nullptr, 10); + e.hotzone = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.insttype = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.shutdowndelay = row[60] ? strtoull(row[60], nullptr, 10) : 5000; e.peqzone = static_cast(atoi(row[61])); e.expansion = static_cast(atoi(row[62])); e.bypass_expansion_check = static_cast(atoi(row[63])); - e.suspendbuffs = static_cast(strtoul(row[64], nullptr, 10)); + e.suspendbuffs = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; e.rain_chance1 = static_cast(atoi(row[65])); e.rain_chance2 = static_cast(atoi(row[66])); e.rain_chance3 = static_cast(atoi(row[67])); @@ -1076,14 +1075,14 @@ public: e.snow_duration2 = static_cast(atoi(row[78])); e.snow_duration3 = static_cast(atoi(row[79])); e.snow_duration4 = static_cast(atoi(row[80])); - e.gravity = strtof(row[81], nullptr); + e.gravity = row[81] ? strtof(row[81], nullptr) : 0.4; e.type = static_cast(atoi(row[82])); e.skylock = static_cast(atoi(row[83])); e.fast_regen_hp = static_cast(atoi(row[84])); e.fast_regen_mana = static_cast(atoi(row[85])); e.fast_regen_endurance = static_cast(atoi(row[86])); e.npc_max_aggro_dist = static_cast(atoi(row[87])); - e.max_movement_update_range = static_cast(strtoul(row[88], nullptr, 10)); + e.max_movement_update_range = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 600; e.min_expansion = static_cast(atoi(row[89])); e.max_expansion = static_cast(atoi(row[90])); e.content_flags = row[91] ? row[91] : ""; @@ -1120,66 +1119,66 @@ public: e.file_name = row[2] ? row[2] : ""; e.long_name = row[3] ? row[3] : ""; e.map_file_name = row[4] ? row[4] : ""; - e.safe_x = strtof(row[5], nullptr); - e.safe_y = strtof(row[6], nullptr); - e.safe_z = strtof(row[7], nullptr); - e.safe_heading = strtof(row[8], nullptr); - e.graveyard_id = strtof(row[9], nullptr); - e.min_level = static_cast(strtoul(row[10], nullptr, 10)); - e.max_level = static_cast(strtoul(row[11], nullptr, 10)); - e.min_status = static_cast(strtoul(row[12], nullptr, 10)); + e.safe_x = row[5] ? strtof(row[5], nullptr) : 0; + e.safe_y = row[6] ? strtof(row[6], nullptr) : 0; + e.safe_z = row[7] ? strtof(row[7], nullptr) : 0; + e.safe_heading = row[8] ? strtof(row[8], nullptr) : 0; + e.graveyard_id = row[9] ? strtof(row[9], nullptr) : 0; + e.min_level = row[10] ? static_cast(strtoul(row[10], nullptr, 10)) : 0; + e.max_level = row[11] ? static_cast(strtoul(row[11], nullptr, 10)) : 255; + e.min_status = row[12] ? static_cast(strtoul(row[12], nullptr, 10)) : 0; e.zoneidnumber = static_cast(atoi(row[13])); - e.version = static_cast(strtoul(row[14], nullptr, 10)); + e.version = row[14] ? static_cast(strtoul(row[14], nullptr, 10)) : 0; e.timezone = static_cast(atoi(row[15])); e.maxclients = static_cast(atoi(row[16])); - e.ruleset = static_cast(strtoul(row[17], nullptr, 10)); + e.ruleset = row[17] ? static_cast(strtoul(row[17], nullptr, 10)) : 0; e.note = row[18] ? row[18] : ""; - e.underworld = strtof(row[19], nullptr); - e.minclip = strtof(row[20], nullptr); - e.maxclip = strtof(row[21], nullptr); - e.fog_minclip = strtof(row[22], nullptr); - e.fog_maxclip = strtof(row[23], nullptr); - e.fog_blue = static_cast(strtoul(row[24], nullptr, 10)); - e.fog_red = static_cast(strtoul(row[25], nullptr, 10)); - e.fog_green = static_cast(strtoul(row[26], nullptr, 10)); - e.sky = static_cast(strtoul(row[27], nullptr, 10)); - e.ztype = static_cast(strtoul(row[28], nullptr, 10)); - e.zone_exp_multiplier = strtof(row[29], nullptr); - e.walkspeed = strtof(row[30], nullptr); - e.time_type = static_cast(strtoul(row[31], nullptr, 10)); - e.fog_red1 = static_cast(strtoul(row[32], nullptr, 10)); - e.fog_green1 = static_cast(strtoul(row[33], nullptr, 10)); - e.fog_blue1 = static_cast(strtoul(row[34], nullptr, 10)); - e.fog_minclip1 = strtof(row[35], nullptr); - e.fog_maxclip1 = strtof(row[36], nullptr); - e.fog_red2 = static_cast(strtoul(row[37], nullptr, 10)); - e.fog_green2 = static_cast(strtoul(row[38], nullptr, 10)); - e.fog_blue2 = static_cast(strtoul(row[39], nullptr, 10)); - e.fog_minclip2 = strtof(row[40], nullptr); - e.fog_maxclip2 = strtof(row[41], nullptr); - e.fog_red3 = static_cast(strtoul(row[42], nullptr, 10)); - e.fog_green3 = static_cast(strtoul(row[43], nullptr, 10)); - e.fog_blue3 = static_cast(strtoul(row[44], nullptr, 10)); - e.fog_minclip3 = strtof(row[45], nullptr); - e.fog_maxclip3 = strtof(row[46], nullptr); - e.fog_red4 = static_cast(strtoul(row[47], nullptr, 10)); - e.fog_green4 = static_cast(strtoul(row[48], nullptr, 10)); - e.fog_blue4 = static_cast(strtoul(row[49], nullptr, 10)); - e.fog_minclip4 = strtof(row[50], nullptr); - e.fog_maxclip4 = strtof(row[51], nullptr); - e.fog_density = strtof(row[52], nullptr); + e.underworld = row[19] ? strtof(row[19], nullptr) : 0; + e.minclip = row[20] ? strtof(row[20], nullptr) : 450; + e.maxclip = row[21] ? strtof(row[21], nullptr) : 450; + e.fog_minclip = row[22] ? strtof(row[22], nullptr) : 450; + e.fog_maxclip = row[23] ? strtof(row[23], nullptr) : 450; + e.fog_blue = row[24] ? static_cast(strtoul(row[24], nullptr, 10)) : 0; + e.fog_red = row[25] ? static_cast(strtoul(row[25], nullptr, 10)) : 0; + e.fog_green = row[26] ? static_cast(strtoul(row[26], nullptr, 10)) : 0; + e.sky = row[27] ? static_cast(strtoul(row[27], nullptr, 10)) : 1; + e.ztype = row[28] ? static_cast(strtoul(row[28], nullptr, 10)) : 1; + e.zone_exp_multiplier = row[29] ? strtof(row[29], nullptr) : 0.00; + e.walkspeed = row[30] ? strtof(row[30], nullptr) : 0.4; + e.time_type = row[31] ? static_cast(strtoul(row[31], nullptr, 10)) : 2; + e.fog_red1 = row[32] ? static_cast(strtoul(row[32], nullptr, 10)) : 0; + e.fog_green1 = row[33] ? static_cast(strtoul(row[33], nullptr, 10)) : 0; + e.fog_blue1 = row[34] ? static_cast(strtoul(row[34], nullptr, 10)) : 0; + e.fog_minclip1 = row[35] ? strtof(row[35], nullptr) : 450; + e.fog_maxclip1 = row[36] ? strtof(row[36], nullptr) : 450; + e.fog_red2 = row[37] ? static_cast(strtoul(row[37], nullptr, 10)) : 0; + e.fog_green2 = row[38] ? static_cast(strtoul(row[38], nullptr, 10)) : 0; + e.fog_blue2 = row[39] ? static_cast(strtoul(row[39], nullptr, 10)) : 0; + e.fog_minclip2 = row[40] ? strtof(row[40], nullptr) : 450; + e.fog_maxclip2 = row[41] ? strtof(row[41], nullptr) : 450; + e.fog_red3 = row[42] ? static_cast(strtoul(row[42], nullptr, 10)) : 0; + e.fog_green3 = row[43] ? static_cast(strtoul(row[43], nullptr, 10)) : 0; + e.fog_blue3 = row[44] ? static_cast(strtoul(row[44], nullptr, 10)) : 0; + e.fog_minclip3 = row[45] ? strtof(row[45], nullptr) : 450; + e.fog_maxclip3 = row[46] ? strtof(row[46], nullptr) : 450; + e.fog_red4 = row[47] ? static_cast(strtoul(row[47], nullptr, 10)) : 0; + e.fog_green4 = row[48] ? static_cast(strtoul(row[48], nullptr, 10)) : 0; + e.fog_blue4 = row[49] ? static_cast(strtoul(row[49], nullptr, 10)) : 0; + e.fog_minclip4 = row[50] ? strtof(row[50], nullptr) : 450; + e.fog_maxclip4 = row[51] ? strtof(row[51], nullptr) : 450; + e.fog_density = row[52] ? strtof(row[52], nullptr) : 0; e.flag_needed = row[53] ? row[53] : ""; e.canbind = static_cast(atoi(row[54])); e.cancombat = static_cast(atoi(row[55])); e.canlevitate = static_cast(atoi(row[56])); e.castoutdoor = static_cast(atoi(row[57])); - e.hotzone = static_cast(strtoul(row[58], nullptr, 10)); - e.insttype = static_cast(strtoul(row[59], nullptr, 10)); - e.shutdowndelay = strtoull(row[60], nullptr, 10); + e.hotzone = row[58] ? static_cast(strtoul(row[58], nullptr, 10)) : 0; + e.insttype = row[59] ? static_cast(strtoul(row[59], nullptr, 10)) : 0; + e.shutdowndelay = row[60] ? strtoull(row[60], nullptr, 10) : 5000; e.peqzone = static_cast(atoi(row[61])); e.expansion = static_cast(atoi(row[62])); e.bypass_expansion_check = static_cast(atoi(row[63])); - e.suspendbuffs = static_cast(strtoul(row[64], nullptr, 10)); + e.suspendbuffs = row[64] ? static_cast(strtoul(row[64], nullptr, 10)) : 0; e.rain_chance1 = static_cast(atoi(row[65])); e.rain_chance2 = static_cast(atoi(row[66])); e.rain_chance3 = static_cast(atoi(row[67])); @@ -1196,14 +1195,14 @@ public: e.snow_duration2 = static_cast(atoi(row[78])); e.snow_duration3 = static_cast(atoi(row[79])); e.snow_duration4 = static_cast(atoi(row[80])); - e.gravity = strtof(row[81], nullptr); + e.gravity = row[81] ? strtof(row[81], nullptr) : 0.4; e.type = static_cast(atoi(row[82])); e.skylock = static_cast(atoi(row[83])); e.fast_regen_hp = static_cast(atoi(row[84])); e.fast_regen_mana = static_cast(atoi(row[85])); e.fast_regen_endurance = static_cast(atoi(row[86])); e.npc_max_aggro_dist = static_cast(atoi(row[87])); - e.max_movement_update_range = static_cast(strtoul(row[88], nullptr, 10)); + e.max_movement_update_range = row[88] ? static_cast(strtoul(row[88], nullptr, 10)) : 600; e.min_expansion = static_cast(atoi(row[89])); e.max_expansion = static_cast(atoi(row[90])); e.content_flags = row[91] ? row[91] : ""; @@ -1269,6 +1268,252 @@ 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 Zone &e + ) + { + std::vector v; + + v.push_back("'" + Strings::Escape(e.short_name) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.file_name) + "'"); + v.push_back("'" + Strings::Escape(e.long_name) + "'"); + v.push_back("'" + Strings::Escape(e.map_file_name) + "'"); + v.push_back(std::to_string(e.safe_x)); + v.push_back(std::to_string(e.safe_y)); + v.push_back(std::to_string(e.safe_z)); + v.push_back(std::to_string(e.safe_heading)); + v.push_back(std::to_string(e.graveyard_id)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.min_status)); + v.push_back(std::to_string(e.zoneidnumber)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.timezone)); + v.push_back(std::to_string(e.maxclients)); + v.push_back(std::to_string(e.ruleset)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + v.push_back(std::to_string(e.underworld)); + v.push_back(std::to_string(e.minclip)); + v.push_back(std::to_string(e.maxclip)); + v.push_back(std::to_string(e.fog_minclip)); + v.push_back(std::to_string(e.fog_maxclip)); + v.push_back(std::to_string(e.fog_blue)); + v.push_back(std::to_string(e.fog_red)); + v.push_back(std::to_string(e.fog_green)); + v.push_back(std::to_string(e.sky)); + v.push_back(std::to_string(e.ztype)); + v.push_back(std::to_string(e.zone_exp_multiplier)); + v.push_back(std::to_string(e.walkspeed)); + v.push_back(std::to_string(e.time_type)); + v.push_back(std::to_string(e.fog_red1)); + v.push_back(std::to_string(e.fog_green1)); + v.push_back(std::to_string(e.fog_blue1)); + v.push_back(std::to_string(e.fog_minclip1)); + v.push_back(std::to_string(e.fog_maxclip1)); + v.push_back(std::to_string(e.fog_red2)); + v.push_back(std::to_string(e.fog_green2)); + v.push_back(std::to_string(e.fog_blue2)); + v.push_back(std::to_string(e.fog_minclip2)); + v.push_back(std::to_string(e.fog_maxclip2)); + v.push_back(std::to_string(e.fog_red3)); + v.push_back(std::to_string(e.fog_green3)); + v.push_back(std::to_string(e.fog_blue3)); + v.push_back(std::to_string(e.fog_minclip3)); + v.push_back(std::to_string(e.fog_maxclip3)); + v.push_back(std::to_string(e.fog_red4)); + v.push_back(std::to_string(e.fog_green4)); + v.push_back(std::to_string(e.fog_blue4)); + v.push_back(std::to_string(e.fog_minclip4)); + v.push_back(std::to_string(e.fog_maxclip4)); + v.push_back(std::to_string(e.fog_density)); + v.push_back("'" + Strings::Escape(e.flag_needed) + "'"); + v.push_back(std::to_string(e.canbind)); + v.push_back(std::to_string(e.cancombat)); + v.push_back(std::to_string(e.canlevitate)); + v.push_back(std::to_string(e.castoutdoor)); + v.push_back(std::to_string(e.hotzone)); + v.push_back(std::to_string(e.insttype)); + v.push_back(std::to_string(e.shutdowndelay)); + v.push_back(std::to_string(e.peqzone)); + v.push_back(std::to_string(e.expansion)); + v.push_back(std::to_string(e.bypass_expansion_check)); + v.push_back(std::to_string(e.suspendbuffs)); + v.push_back(std::to_string(e.rain_chance1)); + v.push_back(std::to_string(e.rain_chance2)); + v.push_back(std::to_string(e.rain_chance3)); + v.push_back(std::to_string(e.rain_chance4)); + v.push_back(std::to_string(e.rain_duration1)); + v.push_back(std::to_string(e.rain_duration2)); + v.push_back(std::to_string(e.rain_duration3)); + v.push_back(std::to_string(e.rain_duration4)); + v.push_back(std::to_string(e.snow_chance1)); + v.push_back(std::to_string(e.snow_chance2)); + v.push_back(std::to_string(e.snow_chance3)); + v.push_back(std::to_string(e.snow_chance4)); + v.push_back(std::to_string(e.snow_duration1)); + v.push_back(std::to_string(e.snow_duration2)); + v.push_back(std::to_string(e.snow_duration3)); + v.push_back(std::to_string(e.snow_duration4)); + v.push_back(std::to_string(e.gravity)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.skylock)); + v.push_back(std::to_string(e.fast_regen_hp)); + v.push_back(std::to_string(e.fast_regen_mana)); + v.push_back(std::to_string(e.fast_regen_endurance)); + v.push_back(std::to_string(e.npc_max_aggro_dist)); + v.push_back(std::to_string(e.max_movement_update_range)); + 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.underworld_teleport_index)); + v.push_back(std::to_string(e.lava_damage)); + v.push_back(std::to_string(e.min_lava_damage)); + + 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("'" + Strings::Escape(e.short_name) + "'"); + v.push_back(std::to_string(e.id)); + v.push_back("'" + Strings::Escape(e.file_name) + "'"); + v.push_back("'" + Strings::Escape(e.long_name) + "'"); + v.push_back("'" + Strings::Escape(e.map_file_name) + "'"); + v.push_back(std::to_string(e.safe_x)); + v.push_back(std::to_string(e.safe_y)); + v.push_back(std::to_string(e.safe_z)); + v.push_back(std::to_string(e.safe_heading)); + v.push_back(std::to_string(e.graveyard_id)); + v.push_back(std::to_string(e.min_level)); + v.push_back(std::to_string(e.max_level)); + v.push_back(std::to_string(e.min_status)); + v.push_back(std::to_string(e.zoneidnumber)); + v.push_back(std::to_string(e.version)); + v.push_back(std::to_string(e.timezone)); + v.push_back(std::to_string(e.maxclients)); + v.push_back(std::to_string(e.ruleset)); + v.push_back("'" + Strings::Escape(e.note) + "'"); + v.push_back(std::to_string(e.underworld)); + v.push_back(std::to_string(e.minclip)); + v.push_back(std::to_string(e.maxclip)); + v.push_back(std::to_string(e.fog_minclip)); + v.push_back(std::to_string(e.fog_maxclip)); + v.push_back(std::to_string(e.fog_blue)); + v.push_back(std::to_string(e.fog_red)); + v.push_back(std::to_string(e.fog_green)); + v.push_back(std::to_string(e.sky)); + v.push_back(std::to_string(e.ztype)); + v.push_back(std::to_string(e.zone_exp_multiplier)); + v.push_back(std::to_string(e.walkspeed)); + v.push_back(std::to_string(e.time_type)); + v.push_back(std::to_string(e.fog_red1)); + v.push_back(std::to_string(e.fog_green1)); + v.push_back(std::to_string(e.fog_blue1)); + v.push_back(std::to_string(e.fog_minclip1)); + v.push_back(std::to_string(e.fog_maxclip1)); + v.push_back(std::to_string(e.fog_red2)); + v.push_back(std::to_string(e.fog_green2)); + v.push_back(std::to_string(e.fog_blue2)); + v.push_back(std::to_string(e.fog_minclip2)); + v.push_back(std::to_string(e.fog_maxclip2)); + v.push_back(std::to_string(e.fog_red3)); + v.push_back(std::to_string(e.fog_green3)); + v.push_back(std::to_string(e.fog_blue3)); + v.push_back(std::to_string(e.fog_minclip3)); + v.push_back(std::to_string(e.fog_maxclip3)); + v.push_back(std::to_string(e.fog_red4)); + v.push_back(std::to_string(e.fog_green4)); + v.push_back(std::to_string(e.fog_blue4)); + v.push_back(std::to_string(e.fog_minclip4)); + v.push_back(std::to_string(e.fog_maxclip4)); + v.push_back(std::to_string(e.fog_density)); + v.push_back("'" + Strings::Escape(e.flag_needed) + "'"); + v.push_back(std::to_string(e.canbind)); + v.push_back(std::to_string(e.cancombat)); + v.push_back(std::to_string(e.canlevitate)); + v.push_back(std::to_string(e.castoutdoor)); + v.push_back(std::to_string(e.hotzone)); + v.push_back(std::to_string(e.insttype)); + v.push_back(std::to_string(e.shutdowndelay)); + v.push_back(std::to_string(e.peqzone)); + v.push_back(std::to_string(e.expansion)); + v.push_back(std::to_string(e.bypass_expansion_check)); + v.push_back(std::to_string(e.suspendbuffs)); + v.push_back(std::to_string(e.rain_chance1)); + v.push_back(std::to_string(e.rain_chance2)); + v.push_back(std::to_string(e.rain_chance3)); + v.push_back(std::to_string(e.rain_chance4)); + v.push_back(std::to_string(e.rain_duration1)); + v.push_back(std::to_string(e.rain_duration2)); + v.push_back(std::to_string(e.rain_duration3)); + v.push_back(std::to_string(e.rain_duration4)); + v.push_back(std::to_string(e.snow_chance1)); + v.push_back(std::to_string(e.snow_chance2)); + v.push_back(std::to_string(e.snow_chance3)); + v.push_back(std::to_string(e.snow_chance4)); + v.push_back(std::to_string(e.snow_duration1)); + v.push_back(std::to_string(e.snow_duration2)); + v.push_back(std::to_string(e.snow_duration3)); + v.push_back(std::to_string(e.snow_duration4)); + v.push_back(std::to_string(e.gravity)); + v.push_back(std::to_string(e.type)); + v.push_back(std::to_string(e.skylock)); + v.push_back(std::to_string(e.fast_regen_hp)); + v.push_back(std::to_string(e.fast_regen_mana)); + v.push_back(std::to_string(e.fast_regen_endurance)); + v.push_back(std::to_string(e.npc_max_aggro_dist)); + v.push_back(std::to_string(e.max_movement_update_range)); + 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.underworld_teleport_index)); + v.push_back(std::to_string(e.lava_damage)); + v.push_back(std::to_string(e.min_lava_damage)); + + 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_ZONE_REPOSITORY_H diff --git a/common/version.h b/common/version.h index 70ee76876..6dd23eb22 100644 --- a/common/version.h +++ b/common/version.h @@ -42,7 +42,7 @@ * Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt */ -#define CURRENT_BINARY_DATABASE_VERSION 9250 +#define CURRENT_BINARY_DATABASE_VERSION 9251 #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9041 diff --git a/utils/scripts/generators/repository-generator.pl b/utils/scripts/generators/repository-generator.pl index 2ce5ad61d..eeecbc356 100644 --- a/utils/scripts/generators/repository-generator.pl +++ b/utils/scripts/generators/repository-generator.pl @@ -319,17 +319,17 @@ foreach my $table_to_generate (@tables) { if ($column_type =~ /unsigned/) { if ($data_type =~ /bigint/) { - $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtoull(row[%s], nullptr, 10);\n", $column_name_formatted, $index); - $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtoull(row[%s], nullptr, 10);\n", $column_name_formatted, $index); + $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtoull(row[%s], nullptr, 10) : %s;\n", $column_name_formatted, $index, $index, $default_value); + $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtoull(row[%s], nullptr, 10) : %s;\n", $column_name_formatted, $index, $index, $default_value); } elsif ($data_type =~ /int/) { - $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = static_cast<%s>(strtoul(row[%s], nullptr, 10));\n", $column_name_formatted, $struct_data_type, $index); - $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = static_cast<%s>(strtoul(row[%s], nullptr, 10));\n", $column_name_formatted, $struct_data_type, $index); + $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? static_cast<%s>(strtoul(row[%s], nullptr, 10)) : %s;\n", $column_name_formatted, $index, $struct_data_type, $index, $default_value); + $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? static_cast<%s>(strtoul(row[%s], nullptr, 10)) : %s;\n", $column_name_formatted, $index, $struct_data_type, $index, $default_value); } } elsif ($data_type =~ /bigint/) { - $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtoll(row[%s], nullptr, 10);\n", $column_name_formatted, $index); - $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtoll(row[%s], nullptr, 10);\n", $column_name_formatted, $index); + $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtoll(row[%s], nullptr, 10) : %s;\n", $column_name_formatted, $index, $index, $default_value); + $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtoll(row[%s], nullptr, 10) : %s;\n", $column_name_formatted, $index, $index, $default_value); } elsif ($data_type =~ /datetime/) { $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtoll(row[%s] ? row[%s] : \"-1\", nullptr, 10);\n", $column_name_formatted, $index, $index); @@ -340,12 +340,12 @@ foreach my $table_to_generate (@tables) { $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = static_cast<%s>(atoi(row[%s]));\n", $column_name_formatted, $struct_data_type, $index); } elsif ($data_type =~ /float|decimal/) { - $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtof(row[%s], nullptr);\n", $column_name_formatted, $index); - $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtof(row[%s], nullptr);\n", $column_name_formatted, $index); + $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtof(row[%s], nullptr) : %s;\n", $column_name_formatted, $index, $index, $default_value); + $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtof(row[%s], nullptr) : %s;\n", $column_name_formatted, $index, $index, $default_value); } elsif ($data_type =~ /double/) { - $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtod(row[%s], nullptr);\n", $column_name_formatted, $index); - $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = strtod(row[%s], nullptr);\n", $column_name_formatted, $index); + $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtod(row[%s], nullptr) : %s;\n", $column_name_formatted, $index, $index, $default_value); + $find_one_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? strtod(row[%s], nullptr) : %s;\n", $column_name_formatted, $index, $index, $default_value); } else { $all_entries .= sprintf("\t\t\te.%-${longest_column_length}s = row[%s] ? row[%s] : \"\";\n", $column_name_formatted, $index, $index); @@ -466,7 +466,7 @@ foreach my $table_to_generate (@tables) { $new_base_repository =~ s/\{\{INSERT_MANY_ENTRIES}}/$insert_many_entries/g; $new_base_repository =~ s/\{\{ALL_ENTRIES}}/$all_entries/g; $new_base_repository =~ s/\{\{GENERATED_DATE}}/$generated_date/g; - $new_base_repository =~ s/\{\{ADDITIONAL_INCLUDES}}/$additional_includes/g; + $new_base_repository =~ s/\{\{ADDITIONAL_INCLUDES}}\n/$additional_includes/g; # Extended repository my $new_repository = $repository_template;