From ee49ad3ce96db41569f865cfa72660a0da7ea28a Mon Sep 17 00:00:00 2001 From: Uleat Date: Mon, 24 Jun 2019 18:13:25 -0400 Subject: [PATCH 1/3] Reworked BotDatabase into a functional add-on for ZoneDatabase --- changelog.txt | 5 + zone/bot.cpp | 88 ++++++++-------- zone/bot.h | 1 - zone/bot_command.cpp | 102 +++++++++---------- zone/bot_database.cpp | 221 ++++++++++++++++++----------------------- zone/bot_database.h | 16 +-- zone/botspellsai.cpp | 2 +- zone/client_packet.cpp | 2 +- zone/net.cpp | 18 +--- zone/questmgr.cpp | 2 +- zone/zonedb.h | 9 ++ 11 files changed, 211 insertions(+), 255 deletions(-) diff --git a/changelog.txt b/changelog.txt index 2ea309812..558a3ac2d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,10 @@ EQEMu Changelog (Started on Sept 24, 2003 15:50) ------------------------------------------------------- +== 6/24/2019 == +Uleat: Reworked BotDatabase into a functional add-on for ZoneDatabase + - Eliminated the database connection associated with class BotDatabase + - All behaviors remain the same with the exception of the calling object + -- To invoke a BotDatabase function, use database.botdb. rather than botdb. == 3/1/2019 == Noudess: Major faction conversion to use client data. diff --git a/zone/bot.cpp b/zone/bot.cpp index 04b4d49c9..b47694103 100644 --- a/zone/bot.cpp +++ b/zone/bot.cpp @@ -158,7 +158,7 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to SetRangerAutoWeaponSelect(false); bool stance_flag = false; - if (!botdb.LoadStance(this, stance_flag) && bot_owner) + if (!database.botdb.LoadStance(this, stance_flag) && bot_owner) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::LoadStance(), GetCleanName()); if (!stance_flag && bot_owner) bot_owner->Message(13, "Could not locate stance for '%s'", GetCleanName()); @@ -177,10 +177,10 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to strcpy(this->name, this->GetCleanName()); memset(&_botInspectMessage, 0, sizeof(InspectMessage_Struct)); - if (!botdb.LoadInspectMessage(GetBotID(), _botInspectMessage) && bot_owner) + if (!database.botdb.LoadInspectMessage(GetBotID(), _botInspectMessage) && bot_owner) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::LoadInspectMessage(), GetCleanName()); - if (!botdb.LoadGuildMembership(GetBotID(), _guildId, _guildRank, _guildName) && bot_owner) + if (!database.botdb.LoadGuildMembership(GetBotID(), _guildId, _guildRank, _guildName) && bot_owner) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::LoadGuildMembership(), GetCleanName()); std::string error_message; @@ -205,12 +205,12 @@ Bot::Bot(uint32 botID, uint32 botOwnerCharacterID, uint32 botSpellsID, double to GenerateBaseStats(); - if (!botdb.LoadTimers(this) && bot_owner) + if (!database.botdb.LoadTimers(this) && bot_owner) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::LoadTimers(), GetCleanName()); LoadAAs(); - if (!botdb.LoadBuffs(this) && bot_owner) + if (!database.botdb.LoadBuffs(this) && bot_owner) bot_owner->Message(13, "&s for '%s'", BotDatabase::fail::LoadBuffs(), GetCleanName()); CalcBotStats(false); @@ -1700,25 +1700,25 @@ bool Bot::Save() if(!GetBotID()) { // New bot record uint32 bot_id = 0; - if (!botdb.SaveNewBot(this, bot_id) || !bot_id) { + if (!database.botdb.SaveNewBot(this, bot_id) || !bot_id) { bot_owner->Message(13, "%s '%s'", BotDatabase::fail::SaveNewBot(), GetCleanName()); return false; } SetBotID(bot_id); } else { // Update existing bot record - if (!botdb.SaveBot(this)) { + if (!database.botdb.SaveBot(this)) { bot_owner->Message(13, "%s '%s'", BotDatabase::fail::SaveBot(), GetCleanName()); return false; } } // All of these continue to process if any fail - if (!botdb.SaveBuffs(this)) + if (!database.botdb.SaveBuffs(this)) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::SaveBuffs(), GetCleanName()); - if (!botdb.SaveTimers(this)) + if (!database.botdb.SaveTimers(this)) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::SaveTimers(), GetCleanName()); - if (!botdb.SaveStance(this)) + if (!database.botdb.SaveStance(this)) bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::SaveStance(), GetCleanName()); if (!SavePet()) @@ -1733,20 +1733,20 @@ bool Bot::DeleteBot() if (!bot_owner) return false; - if (!botdb.DeleteHealRotation(GetBotID())) { + if (!database.botdb.DeleteHealRotation(GetBotID())) { bot_owner->Message(13, "%s", BotDatabase::fail::DeleteHealRotation()); return false; } std::string query = StringFormat("DELETE FROM `bot_heal_rotation_members` WHERE `bot_id` = '%u'", GetBotID()); - auto results = botdb.QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { bot_owner->Message(13, "Failed to delete heal rotation member '%s'", GetCleanName()); return false; } query = StringFormat("DELETE FROM `bot_heal_rotation_targets` WHERE `target_name` LIKE '%s'", GetCleanName()); - results = botdb.QueryDatabase(query); + results = database.QueryDatabase(query); if (!results.Success()) { bot_owner->Message(13, "Failed to delete heal rotation target '%s'", GetCleanName()); return false; @@ -1762,32 +1762,32 @@ bool Bot::DeleteBot() std::string error_message; - if (!botdb.RemoveMemberFromBotGroup(GetBotID())) { + if (!database.botdb.RemoveMemberFromBotGroup(GetBotID())) { bot_owner->Message(13, "%s - '%s'", BotDatabase::fail::RemoveMemberFromBotGroup(), GetCleanName()); return false; } - if (!botdb.DeleteItems(GetBotID())) { + if (!database.botdb.DeleteItems(GetBotID())) { bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::DeleteItems(), GetCleanName()); return false; } - if (!botdb.DeleteTimers(GetBotID())) { + if (!database.botdb.DeleteTimers(GetBotID())) { bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::DeleteTimers(), GetCleanName()); return false; } - if (!botdb.DeleteBuffs(GetBotID())) { + if (!database.botdb.DeleteBuffs(GetBotID())) { bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::DeleteBuffs(), GetCleanName()); return false; } - if (!botdb.DeleteStance(GetBotID())) { + if (!database.botdb.DeleteStance(GetBotID())) { bot_owner->Message(13, "%s for '%s'", BotDatabase::fail::DeleteStance(), GetCleanName()); return false; } - if (!botdb.DeleteBot(GetBotID())) { + if (!database.botdb.DeleteBot(GetBotID())) { bot_owner->Message(13, "%s '%s'", BotDatabase::fail::DeleteBot(), GetCleanName()); return false; } @@ -1831,7 +1831,7 @@ bool Bot::LoadPet() std::string error_message; uint32 pet_index = 0; - if (!botdb.LoadPetIndex(GetBotID(), pet_index)) { + if (!database.botdb.LoadPetIndex(GetBotID(), pet_index)) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::LoadPetIndex(), GetCleanName()); return false; } @@ -1839,7 +1839,7 @@ bool Bot::LoadPet() return true; uint32 saved_pet_spell_id = 0; - if (!botdb.LoadPetSpellID(GetBotID(), saved_pet_spell_id)) { + if (!database.botdb.LoadPetSpellID(GetBotID(), saved_pet_spell_id)) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::LoadPetSpellID(), GetCleanName()); } if (!IsValidSpell(saved_pet_spell_id)) { @@ -1853,7 +1853,7 @@ bool Bot::LoadPet() uint32 pet_hp = 0; uint32 pet_spell_id = 0; - if (!botdb.LoadPetStats(GetBotID(), pet_name, pet_mana, pet_hp, pet_spell_id)) { + if (!database.botdb.LoadPetStats(GetBotID(), pet_name, pet_mana, pet_hp, pet_spell_id)) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::LoadPetStats(), GetCleanName()); return false; } @@ -1868,12 +1868,12 @@ bool Bot::LoadPet() SpellBuff_Struct pet_buffs[PET_BUFF_COUNT]; memset(pet_buffs, 0, (sizeof(SpellBuff_Struct) * PET_BUFF_COUNT)); - if (!botdb.LoadPetBuffs(GetBotID(), pet_buffs)) + if (!database.botdb.LoadPetBuffs(GetBotID(), pet_buffs)) bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::LoadPetBuffs(), GetCleanName()); uint32 pet_items[EQEmu::invslot::EQUIPMENT_COUNT]; memset(pet_items, 0, (sizeof(uint32) * EQEmu::invslot::EQUIPMENT_COUNT)); - if (!botdb.LoadPetItems(GetBotID(), pet_items)) + if (!database.botdb.LoadPetItems(GetBotID(), pet_items)) bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::LoadPetItems(), GetCleanName()); pet_inst->SetPetState(pet_buffs, pet_items); @@ -1912,14 +1912,14 @@ bool Bot::SavePet() std::string error_message; - if (!botdb.SavePetStats(GetBotID(), pet_name_str, pet_inst->GetMana(), pet_inst->GetHP(), pet_inst->GetPetSpellID())) { + if (!database.botdb.SavePetStats(GetBotID(), pet_name_str, pet_inst->GetMana(), pet_inst->GetHP(), pet_inst->GetPetSpellID())) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::SavePetStats(), GetCleanName()); return false; } - if (!botdb.SavePetBuffs(GetBotID(), pet_buffs)) + if (!database.botdb.SavePetBuffs(GetBotID(), pet_buffs)) bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::SavePetBuffs(), GetCleanName()); - if (!botdb.SavePetItems(GetBotID(), pet_items)) + if (!database.botdb.SavePetItems(GetBotID(), pet_items)) bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::SavePetItems(), GetCleanName()); return true; @@ -1933,15 +1933,15 @@ bool Bot::DeletePet() std::string error_message; - if (!botdb.DeletePetItems(GetBotID())) { + if (!database.botdb.DeletePetItems(GetBotID())) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::DeletePetItems(), GetCleanName()); return false; } - if (!botdb.DeletePetBuffs(GetBotID())) { + if (!database.botdb.DeletePetBuffs(GetBotID())) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::DeletePetBuffs(), GetCleanName()); return false; } - if (!botdb.DeletePetStats(GetBotID())) { + if (!database.botdb.DeletePetStats(GetBotID())) { bot_owner->Message(13, "%s for %s's pet", BotDatabase::fail::DeletePetStats(), GetCleanName()); return false; } @@ -3301,7 +3301,7 @@ void Bot::RemoveBotItemBySlot(uint32 slotID, std::string *errorMessage) if(!GetBotID()) return; - if(!botdb.DeleteItemBySlot(GetBotID(), slotID)) + if(!database.botdb.DeleteItemBySlot(GetBotID(), slotID)) *errorMessage = BotDatabase::fail::DeleteItemBySlot(); m_inv.DeleteItem(slotID); @@ -3314,7 +3314,7 @@ void Bot::GetBotItems(EQEmu::InventoryProfile &inv, std::string* errorMessage) if(!GetBotID()) return; - if (!botdb.LoadItems(GetBotID(), inv)) { + if (!database.botdb.LoadItems(GetBotID(), inv)) { *errorMessage = BotDatabase::fail::LoadItems(); return; } @@ -3329,7 +3329,7 @@ uint32 Bot::GetBotItemBySlot(uint32 slotID) if(!GetBotID()) return item_id; - if (!botdb.LoadItemBySlot(GetBotID(), slotID, item_id)) { + if (!database.botdb.LoadItemBySlot(GetBotID(), slotID, item_id)) { if (GetBotOwner() && GetBotOwner()->IsClient()) GetBotOwner()->CastToClient()->Message(13, "%s", BotDatabase::fail::LoadItemBySlot()); } @@ -3418,7 +3418,7 @@ Bot* Bot::LoadBot(uint32 botID) if (!botID) return loaded_bot; - if (!botdb.LoadBot(botID, loaded_bot)) // TODO: Consider update to message handler + if (!database.botdb.LoadBot(botID, loaded_bot)) // TODO: Consider update to message handler return loaded_bot; return loaded_bot; @@ -3433,7 +3433,7 @@ void Bot::LoadAndSpawnAllZonedBots(Client* botOwner) { uint32 TempGroupId = g->GetID(); std::list ActiveBots; // Modified LoadGroupedBotsByGroupID to require a CharacterID - if (!botdb.LoadGroupedBotsByGroupID(botOwner->CharacterID(), TempGroupId, ActiveBots)) { + if (!database.botdb.LoadGroupedBotsByGroupID(botOwner->CharacterID(), TempGroupId, ActiveBots)) { botOwner->Message(13, "%s", BotDatabase::fail::LoadGroupedBotsByGroupID()); return; } @@ -3714,7 +3714,7 @@ void Bot::BotTradeSwapItem(Client* client, int16 lootSlot, const EQEmu::ItemInst void Bot::BotTradeAddItem(uint32 id, const EQEmu::ItemInstance* inst, int16 charges, uint32 equipableSlots, uint16 lootSlot, std::string* errorMessage, bool addToDb) { if(addToDb) { - if (!botdb.SaveItemBySlot(this, lootSlot, inst)) { + if (!database.botdb.SaveItemBySlot(this, lootSlot, inst)) { *errorMessage = BotDatabase::fail::SaveItemBySlot(); return; } @@ -4129,7 +4129,7 @@ void Bot::PerformTradeWithClient(int16 beginSlotID, int16 endSlotID, Client* cli // // TODO: add logging //} - if (!botdb.DeleteItemBySlot(GetBotID(), return_iterator.fromBotSlot)) + if (!database.botdb.DeleteItemBySlot(GetBotID(), return_iterator.fromBotSlot)) client->Message(CC_Red, "%s (slot: %i, name: '%s')", BotDatabase::fail::DeleteItemBySlot(), return_iterator.fromBotSlot, (return_instance ? return_instance->GetItem()->Name : "nullptr")); BotRemoveEquipItem(return_iterator.fromBotSlot); @@ -4144,7 +4144,7 @@ void Bot::PerformTradeWithClient(int16 beginSlotID, int16 endSlotID, Client* cli for (auto& trade_iterator : client_trade) { // TODO: code for stackables - if (!botdb.SaveItemBySlot(this, trade_iterator.toBotSlot, trade_iterator.tradeItemInstance)) + if (!database.botdb.SaveItemBySlot(this, trade_iterator.toBotSlot, trade_iterator.tradeItemInstance)) client->Message(CC_Red, "%s (slot: %i, name: '%s')", BotDatabase::fail::SaveItemBySlot(), trade_iterator.toBotSlot, (trade_iterator.tradeItemInstance ? trade_iterator.tradeItemInstance->GetItem()->Name : "nullptr")); m_inv.PutItem(trade_iterator.toBotSlot, *trade_iterator.tradeItemInstance); @@ -5944,7 +5944,7 @@ void Bot::ProcessGuildInvite(Client* guildOfficer, Bot* botToGuild) { return; } - if (!botdb.SaveGuildMembership(botToGuild->GetBotID(), guildOfficer->GuildID(), GUILD_MEMBER)) { + if (!database.botdb.SaveGuildMembership(botToGuild->GetBotID(), guildOfficer->GuildID(), GUILD_MEMBER)) { guildOfficer->Message(13, "%s for '%s'", BotDatabase::fail::SaveGuildMembership(), botToGuild->GetCleanName()); return; } @@ -5969,16 +5969,16 @@ bool Bot::ProcessGuildRemoval(Client* guildOfficer, std::string botName) { if(guildOfficer && !botName.empty()) { Bot* botToUnGuild = entity_list.GetBotByBotName(botName); if(botToUnGuild) { - if (botdb.SaveGuildMembership(botToUnGuild->GetBotID(), 0, 0)) + if (database.botdb.SaveGuildMembership(botToUnGuild->GetBotID(), 0, 0)) Result = true; } else { uint32 ownerId = 0; - if (!botdb.LoadOwnerID(botName, ownerId)) + if (!database.botdb.LoadOwnerID(botName, ownerId)) guildOfficer->Message(13, "%s for '%s'", BotDatabase::fail::LoadOwnerID(), botName.c_str()); uint32 botId = 0; - if (!botdb.LoadBotID(ownerId, botName, botId)) + if (!database.botdb.LoadBotID(ownerId, botName, botId)) guildOfficer->Message(13, "%s for '%s'", BotDatabase::fail::LoadBotID(), botName.c_str()); - if (botId && botdb.SaveGuildMembership(botId, 0, 0)) + if (botId && database.botdb.SaveGuildMembership(botId, 0, 0)) Result = true; } @@ -9068,7 +9068,7 @@ bool Bot::DyeArmor(int16 slot_id, uint32 rgb, bool all_flag, bool save_flag) if (all_flag) save_slot = -2; - if (!botdb.SaveEquipmentColor(GetBotID(), save_slot, rgb)) { + if (!database.botdb.SaveEquipmentColor(GetBotID(), save_slot, rgb)) { if (GetBotOwner() && GetBotOwner()->IsClient()) GetBotOwner()->CastToClient()->Message(13, "%s", BotDatabase::fail::SaveEquipmentColor()); return false; diff --git a/zone/bot.h b/zone/bot.h index 602b2912d..3b363748a 100644 --- a/zone/bot.h +++ b/zone/bot.h @@ -29,7 +29,6 @@ #include "groups.h" #include "corpse.h" #include "zonedb.h" -#include "bot_database.h" #include "string_ids.h" #include "../common/misc_functions.h" #include "../common/global_define.h" diff --git a/zone/bot_command.cpp b/zone/bot_command.cpp index 0a32a1cb1..d92e501d1 100644 --- a/zone/bot_command.cpp +++ b/zone/bot_command.cpp @@ -59,7 +59,7 @@ #include "bot_command.h" -#include "bot_database.h" +#include "zonedb.h" #include "guild_mgr.h" #include "map.h" #include "doors.h" @@ -1422,7 +1422,7 @@ int bot_command_init(void) } std::map>> bot_command_settings; - botdb.LoadBotCommandSettings(bot_command_settings); + database.botdb.LoadBotCommandSettings(bot_command_settings); auto working_bcl = bot_command_list; for (auto working_bcl_iter : working_bcl) { @@ -1868,11 +1868,11 @@ namespace MyBots std::string group_name = name; uint32 botgroup_id = 0; - if (!botdb.LoadBotGroupIDForLoadBotGroup(bot_owner->CharacterID(), group_name, botgroup_id) || !botgroup_id) + if (!database.botdb.LoadBotGroupIDForLoadBotGroup(bot_owner->CharacterID(), group_name, botgroup_id) || !botgroup_id) return; std::map> botgroup_list; - if (!botdb.LoadBotGroup(group_name, botgroup_list) || botgroup_list.find(botgroup_id) == botgroup_list.end() || !botgroup_list[botgroup_id].size()) + if (!database.botdb.LoadBotGroup(group_name, botgroup_list) || botgroup_list.find(botgroup_id) == botgroup_list.end() || !botgroup_list[botgroup_id].size()) return; std::list selectable_bot_list; @@ -3456,7 +3456,7 @@ void bot_command_owner_option(Client *c, const Seperator *sep) else c->SetBotOptionDeathMarquee(!c->GetBotOptionDeathMarquee()); - botdb.SaveOwnerOptionDeathMarquee(c->CharacterID(), c->GetBotOptionDeathMarquee()); + database.botdb.SaveOwnerOptionDeathMarquee(c->CharacterID(), c->GetBotOptionDeathMarquee()); c->Message(m_action, "Bot 'death marquee' is now %s.", (c->GetBotOptionDeathMarquee() == true ? "enabled" : "disabled")); } else if (!owner_option.compare("statsupdate")) { @@ -3467,7 +3467,7 @@ void bot_command_owner_option(Client *c, const Seperator *sep) else c->SetBotOptionStatsUpdate(!c->GetBotOptionStatsUpdate()); - botdb.SaveOwnerOptionStatsUpdate(c->CharacterID(), c->GetBotOptionStatsUpdate()); + database.botdb.SaveOwnerOptionStatsUpdate(c->CharacterID(), c->GetBotOptionStatsUpdate()); c->Message(m_action, "Bot 'stats update' is now %s.", (c->GetBotOptionStatsUpdate() == true ? "enabled" : "disabled")); } else { @@ -4240,7 +4240,7 @@ void bot_subcommand_bot_clone(Client *c, const Seperator *sep) std::string error_message; bool available_flag = false; - if (!botdb.QueryNameAvailablity(bot_name, available_flag)) { + if (!database.botdb.QueryNameAvailablity(bot_name, available_flag)) { c->Message(m_fail, "%s", BotDatabase::fail::QueryNameAvailablity()); return; } @@ -4252,7 +4252,7 @@ void bot_subcommand_bot_clone(Client *c, const Seperator *sep) uint32 max_bot_count = RuleI(Bots, CreationLimit); uint32 bot_count = 0; - if (!botdb.QueryBotCount(c->CharacterID(), bot_count)) { + if (!database.botdb.QueryBotCount(c->CharacterID(), bot_count)) { c->Message(m_fail, "%s", BotDatabase::fail::QueryBotCount()); return; } @@ -4262,18 +4262,18 @@ void bot_subcommand_bot_clone(Client *c, const Seperator *sep) } uint32 clone_id = 0; - if (!botdb.CreateCloneBot(c->CharacterID(), my_bot->GetBotID(), bot_name, clone_id) || !clone_id) { + if (!database.botdb.CreateCloneBot(c->CharacterID(), my_bot->GetBotID(), bot_name, clone_id) || !clone_id) { c->Message(m_fail, "%s '%s'", BotDatabase::fail::CreateCloneBot(), bot_name.c_str()); return; } int clone_stance = EQEmu::constants::stancePassive; - if (!botdb.LoadStance(my_bot->GetBotID(), clone_stance)) + if (!database.botdb.LoadStance(my_bot->GetBotID(), clone_stance)) c->Message(m_fail, "%s for bot '%s'", BotDatabase::fail::LoadStance(), my_bot->GetCleanName()); - if (!botdb.SaveStance(clone_id, clone_stance)) + if (!database.botdb.SaveStance(clone_id, clone_stance)) c->Message(m_fail, "%s for clone '%s'", BotDatabase::fail::SaveStance(), bot_name.c_str()); - if (!botdb.CreateCloneBotInventory(c->CharacterID(), my_bot->GetBotID(), clone_id)) + if (!database.botdb.CreateCloneBotInventory(c->CharacterID(), my_bot->GetBotID(), clone_id)) c->Message(m_fail, "%s for clone '%s'", BotDatabase::fail::CreateCloneBotInventory(), bot_name.c_str()); c->Message(m_action, "Bot '%s' was successfully cloned to bot '%s'", my_bot->GetCleanName(), bot_name.c_str()); @@ -4521,11 +4521,11 @@ void bot_subcommand_bot_dye_armor(Client *c, const Seperator *sep) if (ab_type == ActionableBots::ABT_All) { if (dye_all) { - if (!botdb.SaveAllArmorColors(c->CharacterID(), rgb_value)) + if (!database.botdb.SaveAllArmorColors(c->CharacterID(), rgb_value)) c->Message(m_fail, "%s", BotDatabase::fail::SaveAllArmorColors()); } else { - if (!botdb.SaveAllArmorColorBySlot(c->CharacterID(), slot_id, rgb_value)) + if (!database.botdb.SaveAllArmorColorBySlot(c->CharacterID(), slot_id, rgb_value)) c->Message(m_fail, "%s", BotDatabase::fail::SaveAllArmorColorBySlot()); } } @@ -4674,7 +4674,7 @@ void bot_subcommand_bot_follow_distance(Client *c, const Seperator *sep) continue; bot_iter->SetFollowDistance(bfd); - if (ab_type != ActionableBots::ABT_All && !botdb.SaveFollowDistance(c->CharacterID(), bot_iter->GetBotID(), bfd)) { + if (ab_type != ActionableBots::ABT_All && !database.botdb.SaveFollowDistance(c->CharacterID(), bot_iter->GetBotID(), bfd)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::SaveFollowDistance(), bot_iter->GetCleanName()); return; } @@ -4683,7 +4683,7 @@ void bot_subcommand_bot_follow_distance(Client *c, const Seperator *sep) } if (ab_type == ActionableBots::ABT_All) { - if (!botdb.SaveAllFollowDistances(c->CharacterID(), bfd)) { + if (!database.botdb.SaveAllFollowDistances(c->CharacterID(), bfd)) { c->Message(m_fail, "%s", BotDatabase::fail::SaveAllFollowDistances()); return; } @@ -4852,7 +4852,7 @@ void bot_subcommand_bot_inspect_message(Client *c, const Seperator *sep) if (set_flag) memcpy(bot_message_struct, client_message_struct, sizeof(InspectMessage_Struct)); - if (ab_type != ActionableBots::ABT_All && !botdb.SaveInspectMessage(bot_iter->GetBotID(), *bot_message_struct)) { + if (ab_type != ActionableBots::ABT_All && !database.botdb.SaveInspectMessage(bot_iter->GetBotID(), *bot_message_struct)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::SaveInspectMessage(), bot_iter->GetCleanName()); return; } @@ -4866,7 +4866,7 @@ void bot_subcommand_bot_inspect_message(Client *c, const Seperator *sep) if (set_flag) memcpy(&bot_message_struct, client_message_struct, sizeof(InspectMessage_Struct)); - if (!botdb.SaveAllInspectMessages(c->CharacterID(), bot_message_struct)) { + if (!database.botdb.SaveAllInspectMessages(c->CharacterID(), bot_message_struct)) { c->Message(m_fail, "%s", BotDatabase::fail::SaveAllInspectMessages()); return; } @@ -4922,7 +4922,7 @@ void bot_subcommand_bot_list(Client *c, const Seperator *sep) } std::list bots_list; - if (!botdb.LoadBotsList(c->CharacterID(), bots_list)) { + if (!database.botdb.LoadBotsList(c->CharacterID(), bots_list)) { c->Message(m_fail, "%s", BotDatabase::fail::LoadBotsList()); return; } @@ -5079,7 +5079,7 @@ void bot_subcommand_bot_spawn(Client *c, const Seperator *sep) if (RuleB(Bots, QuestableSpawnLimit) && !c->GetGM()) { int allowed_bot_count = 0; - if (!botdb.LoadQuestableSpawnCount(c->CharacterID(), allowed_bot_count)) { + if (!database.botdb.LoadQuestableSpawnCount(c->CharacterID(), allowed_bot_count)) { c->Message(m_fail, "%s", BotDatabase::fail::LoadQuestableSpawnCount()); return; } @@ -5100,7 +5100,7 @@ void bot_subcommand_bot_spawn(Client *c, const Seperator *sep) std::string bot_name = sep->arg[1]; uint32 bot_id = 0; - if (!botdb.LoadBotID(c->CharacterID(), bot_name, bot_id)) { + if (!database.botdb.LoadBotID(c->CharacterID(), bot_name, bot_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotID(), bot_name.c_str()); return; } @@ -5273,7 +5273,7 @@ void bot_subcommand_bot_stop_melee_level(Client *c, const Seperator *sep) // [reset] falls through with initialization value my_bot->SetStopMeleeLevel(sml); - if (!botdb.SaveStopMeleeLevel(c->CharacterID(), my_bot->GetBotID(), sml)) + if (!database.botdb.SaveStopMeleeLevel(c->CharacterID(), my_bot->GetBotID(), sml)) c->Message(m_fail, "%s for '%s'", BotDatabase::fail::SaveStopMeleeLevel(), my_bot->GetCleanName()); c->Message(m_action, "Successfully set stop melee level for %s to %u", my_bot->GetCleanName(), sml); @@ -5442,7 +5442,7 @@ void bot_subcommand_bot_toggle_helm(Client *c, const Seperator *sep) bot_iter->SetShowHelm(helm_state); if (ab_type != ActionableBots::ABT_All) { - if (!botdb.SaveHelmAppearance(c->CharacterID(), bot_iter->GetBotID(), bot_iter->GetShowHelm())) { + if (!database.botdb.SaveHelmAppearance(c->CharacterID(), bot_iter->GetBotID(), bot_iter->GetShowHelm())) { c->Message(m_unknown, "%s for '%s'", bot_iter->GetCleanName()); return; } @@ -5464,11 +5464,11 @@ void bot_subcommand_bot_toggle_helm(Client *c, const Seperator *sep) if (ab_type == ActionableBots::ABT_All) { std::string query; if (toggle_helm) { - if (!botdb.ToggleAllHelmAppearances(c->CharacterID())) + if (!database.botdb.ToggleAllHelmAppearances(c->CharacterID())) c->Message(m_fail, "%s", BotDatabase::fail::ToggleAllHelmAppearances()); } else { - if (!botdb.SaveAllHelmAppearances(c->CharacterID(), helm_state)) + if (!database.botdb.SaveAllHelmAppearances(c->CharacterID(), helm_state)) c->Message(m_fail, "%s", BotDatabase::fail::SaveAllHelmAppearances()); } @@ -5627,7 +5627,7 @@ void bot_subcommand_botgroup_add_member(Client *c, const Seperator *sep) } uint32 botgroup_id = 0; - if (!botdb.LoadBotGroupIDByMemberID(new_member->GetBotID(), botgroup_id)) { + if (!database.botdb.LoadBotGroupIDByMemberID(new_member->GetBotID(), botgroup_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDByMemberID(), new_member->GetCleanName()); return; } @@ -5657,7 +5657,7 @@ void bot_subcommand_botgroup_add_member(Client *c, const Seperator *sep) } botgroup_id = 0; - if (!botdb.LoadBotGroupIDByLeaderID(botgroup_leader->GetBotID(), botgroup_id)) { + if (!database.botdb.LoadBotGroupIDByLeaderID(botgroup_leader->GetBotID(), botgroup_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDByLeaderID(), botgroup_leader->GetCleanName()); return; } @@ -5673,14 +5673,14 @@ void bot_subcommand_botgroup_add_member(Client *c, const Seperator *sep) database.SetGroupID(new_member->GetName(), group_inst->GetID(), new_member->GetBotID()); - if (!botdb.AddMemberToBotGroup(botgroup_leader->GetBotID(), new_member->GetBotID())) { + if (!database.botdb.AddMemberToBotGroup(botgroup_leader->GetBotID(), new_member->GetBotID())) { c->Message(m_fail, "%s - %s->%s", BotDatabase::fail::AddMemberToBotGroup(), new_member->GetCleanName(), botgroup_leader->GetCleanName()); Bot::RemoveBotFromGroup(new_member, botgroup_leader->GetGroup()); return; } std::string botgroup_name; - if (!botdb.LoadBotGroupNameByLeaderID(botgroup_leader->GetBotID(), botgroup_name)) + if (!database.botdb.LoadBotGroupNameByLeaderID(botgroup_leader->GetBotID(), botgroup_name)) c->Message(m_fail, "%s", BotDatabase::fail::LoadBotGroupNameByLeaderID()); c->Message(m_action, "Successfully added %s to bot-group %s", new_member->GetCleanName(), botgroup_name.c_str()); @@ -5702,7 +5702,7 @@ void bot_subcommand_botgroup_create(Client *c, const Seperator *sep) } bool extant_flag = false; - if (!botdb.QueryBotGroupExistence(botgroup_name_arg, extant_flag)) { + if (!database.botdb.QueryBotGroupExistence(botgroup_name_arg, extant_flag)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::QueryBotGroupExistence(), botgroup_name_arg.c_str()); return; } @@ -5732,7 +5732,7 @@ void bot_subcommand_botgroup_create(Client *c, const Seperator *sep) } uint32 botgroup_id = 0; - if (!botdb.LoadBotGroupIDByLeaderID(botgroup_leader->GetBotID(), botgroup_id)) { + if (!database.botdb.LoadBotGroupIDByLeaderID(botgroup_leader->GetBotID(), botgroup_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDByLeaderID(), botgroup_leader->GetCleanName()); return; } @@ -5742,7 +5742,7 @@ void bot_subcommand_botgroup_create(Client *c, const Seperator *sep) } botgroup_id = 0; - if (!botdb.LoadBotGroupIDByMemberID(botgroup_leader->GetBotID(), botgroup_id)) { + if (!database.botdb.LoadBotGroupIDByMemberID(botgroup_leader->GetBotID(), botgroup_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDByMemberID(), botgroup_leader->GetCleanName()); return; } @@ -5757,7 +5757,7 @@ void bot_subcommand_botgroup_create(Client *c, const Seperator *sep) return; } - if (!botdb.CreateBotGroup(botgroup_name_arg, botgroup_leader->GetBotID())) { + if (!database.botdb.CreateBotGroup(botgroup_name_arg, botgroup_leader->GetBotID())) { c->Message(m_fail, "%s '%s'", BotDatabase::fail::CreateBotGroup(), botgroup_name_arg.c_str()); safe_delete(group_inst); return; @@ -5787,7 +5787,7 @@ void bot_subcommand_botgroup_delete(Client *c, const Seperator *sep) } uint32 botgroup_id = 0; - if (!botdb.LoadBotGroupIDForLoadBotGroup(c->CharacterID(), botgroup_name_arg, botgroup_id)) { + if (!database.botdb.LoadBotGroupIDForLoadBotGroup(c->CharacterID(), botgroup_name_arg, botgroup_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDForLoadBotGroup(), botgroup_name_arg.c_str()); return; } @@ -5797,7 +5797,7 @@ void bot_subcommand_botgroup_delete(Client *c, const Seperator *sep) } uint32 leader_id = 0; - if (!botdb.LoadLeaderIDByBotGroupID(botgroup_id, leader_id)) { + if (!database.botdb.LoadLeaderIDByBotGroupID(botgroup_id, leader_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadLeaderIDByBotGroupID(), botgroup_name_arg.c_str()); return; } @@ -5811,7 +5811,7 @@ void bot_subcommand_botgroup_delete(Client *c, const Seperator *sep) MyBots::PopulateSBL_BySpawnedBots(c, sbl); std::map> member_list; - if (!botdb.LoadBotGroup(botgroup_name_arg, member_list)) { + if (!database.botdb.LoadBotGroup(botgroup_name_arg, member_list)) { c->Message(m_fail, "%s '%s'", BotDatabase::fail::LoadBotGroup(), botgroup_name_arg.c_str()); return; } @@ -5835,7 +5835,7 @@ void bot_subcommand_botgroup_delete(Client *c, const Seperator *sep) Bot::RemoveBotFromGroup(group_member, group_member->GetGroup()); } - if (!botdb.DeleteBotGroup(leader_id)) { + if (!database.botdb.DeleteBotGroup(leader_id)) { c->Message(m_fail, "%s '%s'", BotDatabase::fail::DeleteBotGroup(), botgroup_name_arg.c_str()); return; } @@ -5853,7 +5853,7 @@ void bot_subcommand_botgroup_list(Client *c, const Seperator *sep) } std::list> botgroups_list; - if (!botdb.LoadBotGroupsListByOwnerID(c->CharacterID(), botgroups_list)) { + if (!database.botdb.LoadBotGroupsListByOwnerID(c->CharacterID(), botgroups_list)) { c->Message(m_fail, "%s", BotDatabase::fail::LoadBotGroupsListByOwnerID()); return; } @@ -5885,7 +5885,7 @@ void bot_subcommand_botgroup_load(Client *c, const Seperator *sep) } bool extant_flag = false; - if (!botdb.QueryBotGroupExistence(botgroup_name_arg, extant_flag)) { + if (!database.botdb.QueryBotGroupExistence(botgroup_name_arg, extant_flag)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::QueryBotGroupExistence(), botgroup_name_arg.c_str()); return; } @@ -5915,13 +5915,13 @@ void bot_subcommand_botgroup_load(Client *c, const Seperator *sep) } uint32 botgroup_id = 0; - if (!botdb.LoadBotGroupIDForLoadBotGroup(c->CharacterID(), botgroup_name_arg, botgroup_id) || !botgroup_id) { + if (!database.botdb.LoadBotGroupIDForLoadBotGroup(c->CharacterID(), botgroup_name_arg, botgroup_id) || !botgroup_id) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroupIDForLoadBotGroup(), botgroup_name_arg.c_str()); return; } std::map> member_list; - if (!botdb.LoadBotGroup(botgroup_name_arg, member_list)) { + if (!database.botdb.LoadBotGroup(botgroup_name_arg, member_list)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadBotGroup(), botgroup_name_arg.c_str()); return; } @@ -5934,7 +5934,7 @@ void bot_subcommand_botgroup_load(Client *c, const Seperator *sep) if (RuleB(Bots, QuestableSpawnLimit)) { int allowed_bot_count = 0; - if (!botdb.LoadQuestableSpawnCount(c->CharacterID(), allowed_bot_count)) { + if (!database.botdb.LoadQuestableSpawnCount(c->CharacterID(), allowed_bot_count)) { c->Message(m_fail, "%s", BotDatabase::fail::LoadQuestableSpawnCount()); return; } @@ -5957,7 +5957,7 @@ void bot_subcommand_botgroup_load(Client *c, const Seperator *sep) } uint32 leader_id = 0; - if (!botdb.LoadLeaderIDByBotGroupName(botgroup_name_arg, leader_id)) { + if (!database.botdb.LoadLeaderIDByBotGroupName(botgroup_name_arg, leader_id)) { c->Message(m_fail, "%s for '%s'", BotDatabase::fail::LoadLeaderIDByBotGroupName(), botgroup_name_arg.c_str()); return; } @@ -6042,7 +6042,7 @@ void bot_subcommand_botgroup_remove_member(Client *c, const Seperator *sep) return; } - if (!botdb.RemoveMemberFromBotGroup(group_member->GetBotID())) { + if (!database.botdb.RemoveMemberFromBotGroup(group_member->GetBotID())) { c->Message(m_fail, "%s - '%s'", BotDatabase::fail::RemoveMemberFromBotGroup(), group_member->GetCleanName()); return; } @@ -6664,7 +6664,7 @@ void bot_subcommand_heal_rotation_create(Client *c, const Seperator *sep) bool member_fail = false; bool target_fail = false; - if (!botdb.LoadHealRotation(creator_member, member_list, target_list, load_flag, member_fail, target_fail)) + if (!database.botdb.LoadHealRotation(creator_member, member_list, target_list, load_flag, member_fail, target_fail)) c->Message(m_fail, "%s", BotDatabase::fail::LoadHealRotation()); if (!load_flag) { @@ -6737,7 +6737,7 @@ void bot_subcommand_heal_rotation_delete(Client *c, const Seperator *sep) } if (all_flag) { - if (botdb.DeleteAllHealRotations(c->CharacterID())) + if (database.botdb.DeleteAllHealRotations(c->CharacterID())) c->Message(m_action, "Succeeded in deleting all heal rotations"); else c->Message(m_fail, "%s", BotDatabase::fail::DeleteAllHealRotations()); @@ -6760,7 +6760,7 @@ void bot_subcommand_heal_rotation_delete(Client *c, const Seperator *sep) return; } - if (!botdb.DeleteHealRotation(current_member->GetBotID())) { + if (!database.botdb.DeleteHealRotation(current_member->GetBotID())) { c->Message(m_fail, "%s", BotDatabase::fail::DeleteHealRotation()); return; } @@ -7047,7 +7047,7 @@ void bot_subcommand_heal_rotation_save(Client *c, const Seperator *sep) bool member_fail = false; bool target_fail = false; - if (!botdb.SaveHealRotation(current_member, member_fail, target_fail)) { + if (!database.botdb.SaveHealRotation(current_member, member_fail, target_fail)) { c->Message(m_fail, "%s", BotDatabase::fail::SaveHealRotation()); return; } @@ -7264,7 +7264,7 @@ void bot_subcommand_inventory_list(Client *c, const Seperator *sep) } uint32 database_count = 0; - if (!botdb.QueryInventoryCount(my_bot->GetBotID(), database_count)) + if (!database.botdb.QueryInventoryCount(my_bot->GetBotID(), database_count)) c->Message(m_unknown, "%s", BotDatabase::fail::QueryInventoryCount()); if (inventory_count != database_count) @@ -7684,7 +7684,7 @@ uint32 helper_bot_create(Client *bot_owner, std::string bot_name, uint8 bot_clas } bool available_flag = false; - if (!botdb.QueryNameAvailablity(bot_name, available_flag)) { + if (!database.botdb.QueryNameAvailablity(bot_name, available_flag)) { bot_owner->Message(m_fail, "%s for '%s'", BotDatabase::fail::QueryNameAvailablity(), bot_name.c_str()); return bot_id; } @@ -7726,7 +7726,7 @@ uint32 helper_bot_create(Client *bot_owner, std::string bot_name, uint8 bot_clas uint32 max_bot_count = RuleI(Bots, CreationLimit); uint32 bot_count = 0; - if (!botdb.QueryBotCount(bot_owner->CharacterID(), bot_count)) { + if (!database.botdb.QueryBotCount(bot_owner->CharacterID(), bot_count)) { bot_owner->Message(m_fail, "%s", BotDatabase::fail::QueryBotCount()); return bot_id; } diff --git a/zone/bot_database.cpp b/zone/bot_database.cpp index 90f184fa8..2aaf677bb 100644 --- a/zone/bot_database.cpp +++ b/zone/bot_database.cpp @@ -23,48 +23,17 @@ #include "../common/string_util.h" #include "../common/eqemu_logsys.h" -#include "bot_database.h" +#include "zonedb.h" #include "bot.h" #include "client.h" -BotDatabase botdb; - - -BotDatabase::BotDatabase() -{ - -} - -BotDatabase::BotDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port) -{ - Connect(host, user, passwd, database, port); -} - -BotDatabase::~BotDatabase() -{ - -} - -bool BotDatabase::Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port) { - uint32 errnum = 0; - char errbuf[MYSQL_ERRMSG_SIZE]; - if (!Open(host, user, passwd, database, port, &errnum, errbuf)) { - Log(Logs::General, Logs::Error, "Failed to connect to bot database: Error: %s", errbuf); - return false; - } - else { - Log(Logs::General, Logs::Status, "Using bot database '%s' at %s:%d", database, host, port); - return true; - } -} - bool BotDatabase::LoadBotCommandSettings(std::map>> &bot_command_settings) { bot_command_settings.clear(); query = "SELECT `bot_command`, `access`, `aliases` FROM `bot_command_settings`"; - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -109,7 +78,7 @@ bool BotDatabase::LoadBotSpellCastingChances() "FROM" " `bot_spell_casting_chances`"; - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success() || !results.RowCount()) return false; @@ -147,7 +116,7 @@ bool BotDatabase::QueryNameAvailablity(const std::string& bot_name, bool& availa return false; query = StringFormat("SELECT `id` FROM `vw_bot_character_mobs` WHERE `name` LIKE '%s' LIMIT 1", bot_name.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (results.RowCount()) @@ -164,7 +133,7 @@ bool BotDatabase::QueryBotCount(const uint32 owner_id, uint32& bot_count) return false; query = StringFormat("SELECT COUNT(`bot_id`) FROM `bot_data` WHERE `owner_id` = '%i'", owner_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -200,7 +169,7 @@ bool BotDatabase::LoadBotsList(const uint32 owner_id, std::listGetClass()) ? (uint8)RuleI(Bots, CasterStopMeleeLevel) : 255) ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -649,7 +618,7 @@ bool BotDatabase::SaveBot(Bot* bot_inst) bot_inst->GetStopMeleeLevel(), bot_inst->GetBotID() ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -662,7 +631,7 @@ bool BotDatabase::DeleteBot(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_data` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -698,7 +667,7 @@ bool BotDatabase::LoadBuffs(Bot* bot_inst) " WHERE `bot_id` = '%u'", bot_inst->GetBotID() ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -817,7 +786,7 @@ bool BotDatabase::SaveBuffs(Bot* bot_inst) bot_buffs[buff_index].caston_z, bot_buffs[buff_index].ExtraDIChance ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteBuffs(bot_inst->GetBotID()); return false; @@ -833,7 +802,7 @@ bool BotDatabase::DeleteBuffs(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_buffs` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -846,7 +815,7 @@ bool BotDatabase::LoadStance(const uint32 bot_id, int& bot_stance) return false; query = StringFormat("SELECT `stance_id` FROM `bot_stances` WHERE `bot_id` = '%u' LIMIT 1", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -866,7 +835,7 @@ bool BotDatabase::LoadStance(Bot* bot_inst, bool& stance_flag) bot_inst->SetDefaultBotStance(); query = StringFormat("SELECT `stance_id` FROM `bot_stances` WHERE `bot_id` = '%u' LIMIT 1", bot_inst->GetBotID()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -888,7 +857,7 @@ bool BotDatabase::SaveStance(const uint32 bot_id, const int bot_stance) return false; query = StringFormat("INSERT INTO `bot_stances` (`bot_id`, `stance_id`) VALUES ('%u', '%u')", bot_id, bot_stance); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteStance(bot_id); return false; @@ -906,7 +875,7 @@ bool BotDatabase::SaveStance(Bot* bot_inst) return false; query = StringFormat("INSERT INTO `bot_stances` (`bot_id`, `stance_id`) VALUES ('%u', '%u')", bot_inst->GetBotID(), bot_inst->GetBotStance()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteStance(bot_inst->GetBotID()); return false; @@ -921,7 +890,7 @@ bool BotDatabase::DeleteStance(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_stances` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -952,7 +921,7 @@ bool BotDatabase::LoadTimers(Bot* bot_inst) bot_inst->GetClass(), bot_inst->GetLevel() ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -994,7 +963,7 @@ bool BotDatabase::SaveTimers(Bot* bot_inst) continue; query = StringFormat("INSERT INTO `bot_timers` (`bot_id`, `timer_id`, `timer_value`) VALUES ('%u', '%u', '%u')", bot_inst->GetBotID(), (timer_index + 1), bot_timers[timer_index]); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteTimers(bot_inst->GetBotID()); return false; @@ -1010,7 +979,7 @@ bool BotDatabase::DeleteTimers(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_timers` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1035,7 +1004,7 @@ bool BotDatabase::LoadGuildMembership(const uint32 bot_id, uint32& guild_id, uin " LIMIT 1", bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1058,7 +1027,7 @@ bool BotDatabase::SaveGuildMembership(const uint32 bot_id, const uint32 guild_id return false; query = StringFormat("INSERT INTO `bot_guild_members` SET `bot_id` = '%u', `guild_id` = '%u', `rank` = '%u'", bot_id, guild_id, guild_rank); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteGuildMembership(bot_id); return false; @@ -1073,7 +1042,7 @@ bool BotDatabase::DeleteGuildMembership(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_guild_members` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1088,7 +1057,7 @@ bool BotDatabase::QueryInventoryCount(const uint32 bot_id, uint32& item_count) return false; query = StringFormat("SELECT COUNT(`inventories_index`) FROM `bot_inventories` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1127,7 +1096,7 @@ bool BotDatabase::LoadItems(const uint32 bot_id, EQEmu::InventoryProfile& invent " ORDER BY `slot_id`", bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1224,7 +1193,7 @@ bool BotDatabase::DeleteItems(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_inventories` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1242,7 +1211,7 @@ bool BotDatabase::LoadItemBySlot(const uint32 bot_id, const uint32 slot_id, uint return false; query = StringFormat("SELECT `item_id` FROM `bot_inventories` WHERE `bot_id` = '%i' AND `slot_id` = '%i' LIMIT 1", bot_id, slot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1329,7 +1298,7 @@ bool BotDatabase::SaveItemBySlot(Bot* bot_inst, const uint32 slot_id, const EQEm (unsigned long)augment_id[4], (unsigned long)augment_id[5] ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteItemBySlot(bot_inst->GetBotID(), slot_id); return false; @@ -1344,7 +1313,7 @@ bool BotDatabase::DeleteItemBySlot(const uint32 bot_id, const uint32 slot_id) return false; query = StringFormat("DELETE FROM `bot_inventories` WHERE `bot_id` = '%u' AND `slot_id` = '%u'", bot_id, slot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1361,7 +1330,7 @@ bool BotDatabase::LoadEquipmentColor(const uint32 bot_id, const uint8 material_s return false; query = StringFormat("SELECT `inst_color` FROM `bot_inventories` WHERE `bot_id` = '%u' AND `slot_id` = '%u' LIMIT 1", bot_id, slot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1397,7 +1366,7 @@ bool BotDatabase::SaveEquipmentColor(const uint32 bot_id, const int16 slot_id, c bot_id, where_clause.c_str() ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1412,7 +1381,7 @@ bool BotDatabase::LoadPetIndex(const uint32 bot_id, uint32& pet_index) return false; query = StringFormat("SELECT `pets_index` FROM `bot_pets` WHERE `bot_id` = '%u' LIMIT 1", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1430,7 +1399,7 @@ bool BotDatabase::LoadPetSpellID(const uint32 bot_id, uint32& pet_spell_id) return false; query = StringFormat("SELECT `spell_id` FROM `bot_pets` WHERE `bot_id` = '%u' LIMIT 1", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1454,7 +1423,7 @@ bool BotDatabase::LoadPetStats(const uint32 bot_id, std::string& pet_name, uint3 return true; query = StringFormat("SELECT `spell_id`, `name`, `mana`, `hp` FROM `bot_pets` WHERE `pets_index` = '%u' LIMIT 1", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1502,7 +1471,7 @@ bool BotDatabase::SavePetStats(const uint32 bot_id, const std::string& pet_name, pet_mana, pet_hp ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeletePetStats(bot_id); return false; @@ -1523,7 +1492,7 @@ bool BotDatabase::DeletePetStats(const uint32 bot_id) return true; query = StringFormat("DELETE FROM `bot_pets` WHERE `pets_index` = '%u'", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1542,7 +1511,7 @@ bool BotDatabase::LoadPetBuffs(const uint32 bot_id, SpellBuff_Struct* pet_buffs) return true; query = StringFormat("SELECT `spell_id`, `caster_level`, `duration` FROM `bot_pet_buffs` WHERE `pets_index` = '%u'", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1608,7 +1577,7 @@ bool BotDatabase::SavePetBuffs(const uint32 bot_id, const SpellBuff_Struct* pet_ pet_buffs[buff_index].level, pet_buffs[buff_index].duration ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeletePetBuffs(bot_id); return false; @@ -1630,7 +1599,7 @@ bool BotDatabase::DeletePetBuffs(const uint32 bot_id) return true; query = StringFormat("DELETE FROM `bot_pet_buffs` WHERE `pets_index` = '%u'", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1649,7 +1618,7 @@ bool BotDatabase::LoadPetItems(const uint32 bot_id, uint32* pet_items) return true; query = StringFormat("SELECT `item_id` FROM `bot_pet_inventories` WHERE `pets_index` = '%u'", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1685,7 +1654,7 @@ bool BotDatabase::SavePetItems(const uint32 bot_id, const uint32* pet_items, boo continue; query = StringFormat("INSERT INTO `bot_pet_inventories` (`pets_index`, `item_id`) VALUES ('%u', '%u')", saved_pet_index, pet_items[item_index]); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeletePetItems(bot_id); return false; @@ -1707,7 +1676,7 @@ bool BotDatabase::DeletePetItems(const uint32 bot_id) return true; query = StringFormat("DELETE FROM `bot_pet_inventories` WHERE `pets_index` = '%u'", saved_pet_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1722,7 +1691,7 @@ bool BotDatabase::LoadInspectMessage(const uint32 bot_id, InspectMessage_Struct& return false; query = StringFormat("SELECT `inspect_message` FROM `bot_inspect_messages` WHERE `bot_id` = '%u' LIMIT 1", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -1755,7 +1724,7 @@ bool BotDatabase::SaveInspectMessage(const uint32 bot_id, const InspectMessage_S return true; query = StringFormat("INSERT INTO `bot_inspect_messages` (`bot_id`, `inspect_message`) VALUES ('%u', '%s')", bot_id, bot_message.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteInspectMessage(bot_id); return false; @@ -1770,7 +1739,7 @@ bool BotDatabase::DeleteInspectMessage(const uint32 bot_id) return false; query = StringFormat("DELETE FROM `bot_inspect_messages` WHERE `bot_id` = '%u'", bot_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1792,7 +1761,7 @@ bool BotDatabase::SaveAllInspectMessages(const uint32 owner_id, const InspectMes return true; query = StringFormat("INSERT INTO `bot_inspect_messages` (`bot_id`, `inspect_message`) SELECT `bot_id`, '%s' inspect_message FROM `bot_data` WHERE `owner_id` = '%u'", bot_message.c_str(), owner_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteAllInspectMessages(owner_id); return false; @@ -1807,7 +1776,7 @@ bool BotDatabase::DeleteAllInspectMessages(const uint32 owner_id) return false; query = StringFormat("DELETE FROM `bot_inspect_messages` WHERE `bot_id` IN (SELECT `bot_id` FROM `bot_data` WHERE `owner_id` = '%u')", owner_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1832,7 +1801,7 @@ bool BotDatabase::SaveAllArmorColorBySlot(const uint32 owner_id, const int16 slo EQEmu::invslot::slotHead, EQEmu::invslot::slotChest, EQEmu::invslot::slotArms, EQEmu::invslot::slotWrist1, EQEmu::invslot::slotWrist2, EQEmu::invslot::slotHands, EQEmu::invslot::slotLegs, EQEmu::invslot::slotFeet, slot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1855,7 +1824,7 @@ bool BotDatabase::SaveAllArmorColors(const uint32 owner_id, const uint32 rgb_val rgb_value, EQEmu::invslot::slotHead, EQEmu::invslot::slotChest, EQEmu::invslot::slotArms, EQEmu::invslot::slotWrist1, EQEmu::invslot::slotWrist2, EQEmu::invslot::slotHands, EQEmu::invslot::slotLegs, EQEmu::invslot::slotFeet ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1876,7 +1845,7 @@ bool BotDatabase::SaveHelmAppearance(const uint32 owner_id, const uint32 bot_id, owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1895,7 +1864,7 @@ bool BotDatabase::SaveAllHelmAppearances(const uint32 owner_id, const bool show_ (show_flag ? 1 : 0), owner_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1915,7 +1884,7 @@ bool BotDatabase::ToggleHelmAppearance(const uint32 owner_id, const uint32 bot_i owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1933,7 +1902,7 @@ bool BotDatabase::ToggleAllHelmAppearances(const uint32 owner_id) " WHERE `owner_id` = '%u'", owner_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1954,7 +1923,7 @@ bool BotDatabase::SaveFollowDistance(const uint32 owner_id, const uint32 bot_id, owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -1973,7 +1942,7 @@ bool BotDatabase::SaveAllFollowDistances(const uint32 owner_id, const uint32 fol follow_distance, owner_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2091,7 +2060,7 @@ bool BotDatabase::CreateCloneBot(const uint32 owner_id, const uint32 bot_id, con owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2152,7 +2121,7 @@ bool BotDatabase::CreateCloneBotInventory(const uint32 owner_id, const uint32 bo owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteItems(clone_id); return false; @@ -2175,7 +2144,7 @@ bool BotDatabase::SaveStopMeleeLevel(const uint32 owner_id, const uint32 bot_id, owner_id, bot_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2192,12 +2161,12 @@ bool BotDatabase::LoadOwnerOptions(Client *owner) " WHERE `owner_id` = '%u'", owner->CharacterID() ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) { query = StringFormat("REPLACE INTO `bot_owner_options` (`owner_id`) VALUES ('%u')", owner->CharacterID()); - results = QueryDatabase(query); + results = database.QueryDatabase(query); return false; } @@ -2221,7 +2190,7 @@ bool BotDatabase::SaveOwnerOptionDeathMarquee(const uint32 owner_id, const bool (flag == true ? 1 : 0), owner_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2240,7 +2209,7 @@ bool BotDatabase::SaveOwnerOptionStatsUpdate(const uint32 owner_id, const bool f (flag == true ? 1 : 0), owner_id ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2255,7 +2224,7 @@ bool BotDatabase::QueryBotGroupExistence(const std::string& group_name, bool& ex return false; query = StringFormat("SELECT `group_name` FROM `vw_bot_groups` WHERE `group_name` LIKE '%s' LIMIT 1", group_name.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2272,7 +2241,7 @@ bool BotDatabase::LoadBotGroupIDByBotGroupName(const std::string& group_name, ui return false; query = StringFormat("SELECT `groups_index` FROM `bot_groups` WHERE `group_name` = '%s' LIMIT 1", group_name.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2290,7 +2259,7 @@ bool BotDatabase::LoadBotGroupIDByLeaderID(const uint32 leader_id, uint32& botgr return false; query = StringFormat("SELECT `groups_index` FROM `bot_groups` WHERE `group_leader_id` = '%u' LIMIT 1", leader_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2308,7 +2277,7 @@ bool BotDatabase::LoadBotGroupIDByMemberID(const uint32 member_id, uint32& botgr return false; query = StringFormat("SELECT `groups_index` FROM `bot_group_members` WHERE `bot_id` = '%u' LIMIT 1", member_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2326,7 +2295,7 @@ bool BotDatabase::LoadLeaderIDByBotGroupName(const std::string& group_name, uint return false; query = StringFormat("SELECT `group_leader_id` FROM `bot_groups` WHERE `group_name` = '%s' LIMIT 1", group_name.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2344,7 +2313,7 @@ bool BotDatabase::LoadLeaderIDByBotGroupID(const uint32 group_id, uint32& leader return false; query = StringFormat("SELECT `group_leader_id` FROM `bot_groups` WHERE `groups_index` = '%u' LIMIT 1", group_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2362,7 +2331,7 @@ bool BotDatabase::LoadBotGroupNameByBotGroupID(const uint32 group_id, std::strin false; query = StringFormat("SELECT `group_name` FROM `bot_groups` WHERE `groups_index` = '%u' LIMIT 1", group_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2380,7 +2349,7 @@ bool BotDatabase::LoadBotGroupNameByLeaderID(const uint32 leader_id, std::string return false; query = StringFormat("SELECT `group_name` FROM `bot_groups` WHERE `group_leader_id` = '%u' LIMIT 1", leader_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2404,7 +2373,7 @@ bool BotDatabase::CreateBotGroup(const std::string& group_name, const uint32 lea return true; query = StringFormat("INSERT INTO `bot_groups` (`group_leader_id`, `group_name`) VALUES ('%u', '%s')", leader_id, group_name.c_str()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { DeleteBotGroup(leader_id); return false; @@ -2417,7 +2386,7 @@ bool BotDatabase::CreateBotGroup(const std::string& group_name, const uint32 lea } query = StringFormat("INSERT INTO `bot_group_members` (`groups_index`, `bot_id`) VALUES ('%u', '%u')", botgroup_id, leader_id); - results = QueryDatabase(query); + results = database.QueryDatabase(query); if (!results.Success()) { RemoveMemberFromBotGroup(leader_id); return false; @@ -2438,12 +2407,12 @@ bool BotDatabase::DeleteBotGroup(const uint32 leader_id) return true; query = StringFormat("DELETE FROM `bot_group_members` WHERE `groups_index` = '%u'", botgroup_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; query = StringFormat("DELETE FROM `bot_groups` WHERE `groups_index` = '%u'", botgroup_id); - results = QueryDatabase(query); + results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2462,7 +2431,7 @@ bool BotDatabase::AddMemberToBotGroup(const uint32 leader_id, const uint32 membe return true; query = StringFormat("INSERT INTO `bot_group_members` (`groups_index`, `bot_id`) VALUES ('%u', '%u')", botgroup_id, member_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { RemoveMemberFromBotGroup(member_id); return false; @@ -2483,7 +2452,7 @@ bool BotDatabase::RemoveMemberFromBotGroup(const uint32 member_id) return DeleteBotGroup(member_id); query = StringFormat("DELETE FROM `bot_group_members` WHERE `bot_id` = '%u'", member_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2496,7 +2465,7 @@ bool BotDatabase::LoadBotGroupIDForLoadBotGroup(const uint32 owner_id, const std return false; query = StringFormat("SELECT `groups_index`, `group_name` FROM `vw_bot_groups` WHERE `owner_id` = '%u'", owner_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2524,7 +2493,7 @@ bool BotDatabase::LoadBotGroup(const std::string& group_name, std::map& member_lis " LIMIT 1", hr_index ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; if (!results.RowCount()) @@ -2681,7 +2650,7 @@ bool BotDatabase::LoadHealRotationMembers(const uint32 hr_index, std::listMemberOfHealRotation())->ArmorTypeCriticalHPRatio(ARMOR_TYPE_CHAIN)), ((*hr_member->MemberOfHealRotation())->ArmorTypeCriticalHPRatio(ARMOR_TYPE_PLATE)) ); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2792,7 +2761,7 @@ bool BotDatabase::SaveHealRotation(Bot* hr_member, bool& member_fail, bool& targ continue; query = StringFormat("INSERT INTO `bot_heal_rotation_members` (`heal_rotation_index`, `bot_id`) VALUES ('%u', '%u')", hr_index, member_iter->GetBotID()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { member_fail = true; break; @@ -2806,7 +2775,7 @@ bool BotDatabase::SaveHealRotation(Bot* hr_member, bool& member_fail, bool& targ continue; query = StringFormat("INSERT INTO `bot_heal_rotation_targets` (`heal_rotation_index`, `target_name`) VALUES ('%u', '%s')", hr_index, target_iter->GetCleanName()); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) { target_fail = true; break; @@ -2828,17 +2797,17 @@ bool BotDatabase::DeleteHealRotation(const uint32 creator_id) return true; query = StringFormat("DELETE FROM `bot_heal_rotation_targets` WHERE `heal_rotation_index` = '%u'", hr_index); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; query = StringFormat("DELETE FROM `bot_heal_rotation_members` WHERE `heal_rotation_index` = '%u'", hr_index); - results = QueryDatabase(query); + results = database.QueryDatabase(query); if (!results.Success()) return false; query = StringFormat("DELETE FROM `bot_heal_rotations` WHERE `heal_rotation_index` = '%u'", hr_index); - results = QueryDatabase(query); + results = database.QueryDatabase(query); if (!results.Success()) return false; @@ -2851,7 +2820,7 @@ bool BotDatabase::DeleteAllHealRotations(const uint32 owner_id) return false; query = StringFormat("SELECT `bot_id` FROM `bot_heal_rotations` WHERE `bot_id` IN (SELECT `bot_id` FROM `bot_data` WHERE `owner_id` = '%u')", owner_id); - auto results = QueryDatabase(query); + auto results = database.QueryDatabase(query); if (!results.Success()) return false; diff --git a/zone/bot_database.h b/zone/bot_database.h index 613c73967..a94d2a902 100644 --- a/zone/bot_database.h +++ b/zone/bot_database.h @@ -22,17 +22,15 @@ #ifdef BOTS -#include "../common/dbcore.h" -#include "../common/eq_packet_structs.h" - #include #include #include class Bot; -struct BotsAvailableList; class Client; +struct BotsAvailableList; +struct InspectMessage_Struct; namespace EQEmu { @@ -41,15 +39,9 @@ namespace EQEmu } -class BotDatabase : public DBcore +class BotDatabase { public: - BotDatabase(); - BotDatabase(const char* host, const char* user, const char* passwd, const char* database, uint32 port); - virtual ~BotDatabase(); - - bool Connect(const char* host, const char* user, const char* passwd, const char* database, uint32 port); - bool LoadBotCommandSettings(std::map>> &bot_command_settings); bool LoadBotSpellCastingChances(); @@ -297,8 +289,6 @@ public: std::string query; }; -extern BotDatabase botdb; - #endif #endif // BOTS diff --git a/zone/botspellsai.cpp b/zone/botspellsai.cpp index 5049f934d..3ec7e7202 100644 --- a/zone/botspellsai.cpp +++ b/zone/botspellsai.cpp @@ -2668,7 +2668,7 @@ uint8 Bot::GetChanceToCastBySpellType(uint32 spellType) type_index |= pD; } - return botdb.GetSpellCastingChance(spell_type_index, class_index, stance_index, type_index); + return database.botdb.GetSpellCastingChance(spell_type_index, class_index, stance_index, type_index); } #endif diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 554cbeba7..5cf36c946 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1528,7 +1528,7 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) } #ifdef BOTS - botdb.LoadOwnerOptions(this); + database.botdb.LoadOwnerOptions(this); // TODO: mod below function for loading spawned botgroups Bot::LoadAndSpawnAllZonedBots(this); #endif diff --git a/zone/net.cpp b/zone/net.cpp index 522512f51..d21653735 100644 --- a/zone/net.cpp +++ b/zone/net.cpp @@ -52,7 +52,6 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include "command.h" #ifdef BOTS #include "bot_command.h" -#include "bot_database.h" #endif #include "zone_config.h" #include "titles.h" @@ -235,18 +234,6 @@ int main(int argc, char** argv) { return 1; } -#ifdef BOTS - if (!botdb.Connect( - Config->DatabaseHost.c_str(), - Config->DatabaseUsername.c_str(), - Config->DatabasePassword.c_str(), - Config->DatabaseDB.c_str(), - Config->DatabasePort)) { - Log(Logs::General, Logs::Error, "Cannot continue without a bots database connection."); - return 1; - } -#endif - /* Register Log System and Settings */ LogSys.OnLogHookCallBackZone(&Zone::GMSayHookCallBackProcess); database.LoadLogSettings(LogSys.log_settings); @@ -393,7 +380,7 @@ int main(int argc, char** argv) { Log(Logs::General, Logs::Zone_Server, "%d bot commands loaded", botretval); Log(Logs::General, Logs::Zone_Server, "Loading bot spell casting chances"); - if (!botdb.LoadBotSpellCastingChances()) + if (!database.botdb.LoadBotSpellCastingChances()) Log(Logs::General, Logs::Error, "Bot spell casting chances loading FAILED"); #endif @@ -544,9 +531,6 @@ int main(int argc, char** argv) { if (InterserverTimer.Check()) { InterserverTimer.Start(); database.ping(); -#ifdef BOTS - botdb.ping(); -#endif entity_list.UpdateWho(); } }; diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index b4d115b38..42cb39503 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -2181,7 +2181,7 @@ bool QuestManager::createBot(const char *name, const char *lastname, uint8 level std::string test_name = name; bool available_flag = false; - if(!botdb.QueryNameAvailablity(test_name, available_flag)) { + if(!database.botdb.QueryNameAvailablity(test_name, available_flag)) { initiator->Message(0, "%s for '%s'", BotDatabase::fail::QueryNameAvailablity(), (char*)name); return false; } diff --git a/zone/zonedb.h b/zone/zonedb.h index 843bdace5..ee44e2de0 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -11,6 +11,10 @@ #include "aa_ability.h" #include "event_codes.h" +#ifdef BOTS +#include "bot_database.h" +#endif + class Client; class Corpse; class Merc; @@ -535,6 +539,11 @@ public: /* Things which really dont belong here... */ int16 CommandRequirement(const char* commandname); +#ifdef BOTS + // bot database add-on to eliminate the need for a second database connection + BotDatabase botdb; +#endif + protected: void ZDBInitVars(); From 6c73fee075d81ff8442c2f666e0af938b91ac142 Mon Sep 17 00:00:00 2001 From: Uleat Date: Thu, 27 Jun 2019 19:00:02 -0400 Subject: [PATCH 2/3] Added bot command 'petgetlost' to dismiss summoned pets --- common/version.h | 2 +- .../sql/git/bots/bots_db_update_manifest.txt | 1 + .../required/2019_06_27_bots_pet_get_lost.sql | 1 + zone/bot_command.cpp | 37 ++++++++++++++++++- zone/bot_command.h | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 utils/sql/git/bots/required/2019_06_27_bots_pet_get_lost.sql diff --git a/common/version.h b/common/version.h index 1684fe0d2..19d05220b 100644 --- a/common/version.h +++ b/common/version.h @@ -34,7 +34,7 @@ #define CURRENT_BINARY_DATABASE_VERSION 9139 #ifdef BOTS - #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9023 + #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9024 #else #define CURRENT_BINARY_BOTS_DATABASE_VERSION 0 // must be 0 #endif diff --git a/utils/sql/git/bots/bots_db_update_manifest.txt b/utils/sql/git/bots/bots_db_update_manifest.txt index 21aa4161b..982200f2a 100644 --- a/utils/sql/git/bots/bots_db_update_manifest.txt +++ b/utils/sql/git/bots/bots_db_update_manifest.txt @@ -22,6 +22,7 @@ 9021|2018_10_09_bots_owner_options.sql|SHOW TABLES LIKE 'bot_owner_options'|empty| 9022|2019_02_07_bots_stance_type_update.sql|SELECT * FROM `bot_spell_casting_chances` WHERE `spell_type_index` = '255' AND `class_id` = '255' AND `stance_index` = '0'|not_empty| 9023|2019_06_22_bots_owner_option_stats_update.sql|SHOW COLUMNS FROM `bot_owner_options` LIKE 'stats_update'|empty| +9024|2019_06_27_bots_pet_get_lost.sql|SELECT `bot_command` FROM `bot_command_settings` WHERE `bot_command` LIKE 'petgetlost'|empty| # Upgrade conditions: # This won't be needed after this system is implemented, but it is used database that are not diff --git a/utils/sql/git/bots/required/2019_06_27_bots_pet_get_lost.sql b/utils/sql/git/bots/required/2019_06_27_bots_pet_get_lost.sql new file mode 100644 index 000000000..7d0c36624 --- /dev/null +++ b/utils/sql/git/bots/required/2019_06_27_bots_pet_get_lost.sql @@ -0,0 +1 @@ +INSERT INTO `bot_command_settings`(`bot_command`, `access`, `aliases`) VALUES ('petgetlost', '0', 'pgl'); diff --git a/zone/bot_command.cpp b/zone/bot_command.cpp index d92e501d1..69191d991 100644 --- a/zone/bot_command.cpp +++ b/zone/bot_command.cpp @@ -1401,7 +1401,8 @@ int bot_command_init(void) bot_command_add("movementspeed", "Orders a bot to cast a movement speed enhancement spell", 0, bot_command_movement_speed) || bot_command_add("owneroption", "Sets options available to bot owners", 0, bot_command_owner_option) || bot_command_add("pet", "Lists the available bot pet [subcommands]", 0, bot_command_pet) || - bot_command_add("petremove", "Orders a bot to remove its pet", 0, bot_subcommand_pet_remove) || + bot_command_add("petgetlost", "Orders a bot to remove its summoned pet", 0, bot_subcommand_pet_get_lost) || + bot_command_add("petremove", "Orders a bot to remove its charmed pet", 0, bot_subcommand_pet_remove) || bot_command_add("petsettype", "Orders a Magician bot to use a specified pet type", 0, bot_subcommand_pet_set_type) || bot_command_add("picklock", "Orders a capable bot to pick the lock of the closest door", 0, bot_command_pick_lock) || bot_command_add("portal", "Orders a Wizard bot to open a magical doorway to a specified destination", 0, bot_subcommand_portal) || @@ -3479,12 +3480,13 @@ void bot_command_pet(Client *c, const Seperator *sep) { /* VS2012 code - begin */ std::list subcommand_list; + subcommand_list.push_back("petgetlost"); subcommand_list.push_back("petremove"); subcommand_list.push_back("petsettype"); /* VS2012 code - end */ /* VS2013 code - const std::list subcommand_list = { "petremove", "petsettype" }; + const std::list subcommand_list = { "petgetlost", "petremove", "petsettype" }; */ if (helper_command_alias_fail(c, "bot_command_pet", sep->arg[0], "pet")) @@ -7433,6 +7435,37 @@ void bot_subcommand_inventory_window(Client *c, const Seperator *sep) c->SendPopupToClient(window_title.c_str(), window_text.c_str()); } +void bot_subcommand_pet_get_lost(Client *c, const Seperator *sep) +{ + if (helper_command_alias_fail(c, "bot_subcommand_pet_get_lost", sep->arg[0], "petgetlost")) + return; + if (helper_is_help_or_usage(sep->arg[1])) { + c->Message(m_usage, "usage: %s ([actionable: target | byname | ownergroup | botgroup | targetgroup | namesgroup | healrotation | spawned] ([actionable_name]))", sep->arg[0]); + return; + } + int ab_mask = ActionableBots::ABM_NoFilter; + + std::list sbl; + if (ActionableBots::PopulateSBL(c, sep->arg[1], sbl, ab_mask, sep->arg[2]) == ActionableBots::ABT_None) + return; + + int summoned_pet = 0; + for (auto bot_iter : sbl) { + if (!bot_iter->GetPet() || bot_iter->GetPet()->IsCharmed()) + continue; + + bot_iter->GetPet()->Say_StringID(PET_GETLOST_STRING); + bot_iter->GetPet()->Depop(false); + bot_iter->SetPetID(0); + database.botdb.DeletePetItems(bot_iter->GetBotID()); + database.botdb.DeletePetBuffs(bot_iter->GetBotID()); + database.botdb.DeletePetStats(bot_iter->GetBotID()); + ++summoned_pet; + } + + c->Message(m_action, "%i of your bots released their summoned pet%s", summoned_pet, (summoned_pet == 1) ? "" : "s"); +} + void bot_subcommand_pet_remove(Client *c, const Seperator *sep) { if (helper_command_alias_fail(c, "bot_subcommand_pet_remove", sep->arg[0], "petremove")) diff --git a/zone/bot_command.h b/zone/bot_command.h index 603852b38..d60238f23 100644 --- a/zone/bot_command.h +++ b/zone/bot_command.h @@ -652,6 +652,7 @@ void bot_subcommand_inventory_give(Client *c, const Seperator *sep); void bot_subcommand_inventory_list(Client *c, const Seperator *sep); void bot_subcommand_inventory_remove(Client *c, const Seperator *sep); void bot_subcommand_inventory_window(Client *c, const Seperator *sep); +void bot_subcommand_pet_get_lost(Client *c, const Seperator *sep); void bot_subcommand_pet_remove(Client *c, const Seperator *sep); void bot_subcommand_pet_set_type(Client *c, const Seperator *sep); void bot_subcommand_portal(Client *c, const Seperator *sep); From d7c110041a82dfead51c2e781d6a3650670bc278 Mon Sep 17 00:00:00 2001 From: Uleat Date: Thu, 27 Jun 2019 21:08:08 -0400 Subject: [PATCH 3/3] Added full support in eqemu_server.pl for downloading both stable and unstable bots binaries --- utils/scripts/eqemu_server.pl | 40 +++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/utils/scripts/eqemu_server.pl b/utils/scripts/eqemu_server.pl index bd17ad435..576c90397 100644 --- a/utils/scripts/eqemu_server.pl +++ b/utils/scripts/eqemu_server.pl @@ -812,7 +812,8 @@ sub show_menu_prompt { print ">>> Windows\n"; print " [windows_server_download] Updates server via latest 'stable' code\n"; print " [windows_server_latest] Updates server via latest commit 'unstable'\n"; - print " [windows_server_download_bots] Updates server (bots) from latest 'stable'\n"; + print " [windows_server_download_bots] Updates server (bots) via latest 'stable'\n"; + print " [windows_server_latest_bots] Updates server (bots) via latest commit 'unstable'\n"; print " [fetch_dlls] Grabs dll's needed to run windows binaries\n"; print " [setup_loginserver] Sets up loginserver for Windows\n"; } @@ -876,6 +877,10 @@ sub show_menu_prompt { fetch_latest_windows_binaries_bots(); $dc = 1; } + elsif ($input eq "windows_server_latest_bots") { + fetch_latest_windows_appveyor_bots(); + $dc = 1; + } elsif ($input eq "fetch_dlls") { fetch_server_dlls(); $dc = 1; @@ -1400,14 +1405,37 @@ sub fetch_latest_windows_binaries { rmtree('updates_staged'); } -sub fetch_latest_windows_binaries_bots { - print "[Update] Fetching Latest Windows Binaries (unstable) with Bots...\n"; +sub fetch_latest_windows_appveyor_bots { + print "[Update] Fetching Latest Windows Binaries with Bots (unstable) from Appveyor... \n"; get_remote_file("https://ci.appveyor.com/api/projects/KimLS/server/artifacts/eqemu-x86-bots.zip", "updates_staged/eqemu-x86-bots.zip", 1); - #::: old repository kept for reference until no issues reported - #::: get_remote_file($install_repository_request_url . "master_windows_build_bots.zip", "updates_staged/master_windows_build_bots.zip", 1); + + print "[Update] Fetched Latest Windows Binaries (unstable) from Appveyor... \n"; + print "[Update] Extracting... --- \n"; + unzip('updates_staged/eqemu-x86-bots.zip', 'updates_staged/binaries/'); + my @files; + my $start_dir = "updates_staged/binaries"; + find( + sub { push @files, $File::Find::name unless -d; }, + $start_dir + ); + for my $file (@files) { + $destination_file = $file; + $destination_file =~ s/updates_staged\/binaries\///g; + print "[Update] Installing :: " . $destination_file . "\n"; + copy_file($file, $destination_file); + } + print "[Update] Done\n"; + + rmtree('updates_staged'); +} + +sub fetch_latest_windows_binaries_bots { + print "[Update] Fetching Latest Windows Binaries with Bots...\n"; + get_remote_file($install_repository_request_url . "master_windows_build_bots.zip", "updates_staged/master_windows_build_bots.zip", 1); + print "[Update] Fetched Latest Windows Binaries with Bots...\n"; print "[Update] Extracting...\n"; - unzip('updates_staged/eqemu-x86-bots.zip', 'updates_staged/binaries/'); + unzip('updates_staged/master_windows_build_bots.zip', 'updates_staged/binaries/'); my @files; my $start_dir = "updates_staged/binaries"; find(