From a7f412b4283752aad0f8007a64e88255110a1ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E4=BD=A9=E8=8C=B9?= Date: Tue, 22 Mar 2022 11:04:21 -0600 Subject: [PATCH] Fix corrupt item cache crashes, bot whispers, trade crashes --- .../playerbots_arena_team_names.sql | 16 ++-- sql/characters/playerbots_guild_names.sql | 12 +-- sql/characters/playerbots_names.sql | 10 +- .../base/playerbots_item_info_cache.sql | 91 ++++++++++--------- sql/world/world_charsections_dbc.sql | 2 +- sql/world/world_emotetextsound_dbc.sql | 2 +- src/Helpers.h | 2 + src/PlayerbotAI.cpp | 2 +- src/PlayerbotAIConfig.h | 2 +- src/PlayerbotFactory.cpp | 4 +- src/PlayerbotMgr.cpp | 1 + src/RandomItemMgr.cpp | 2 +- src/RandomPlayerbotFactory.h | 1 + src/strategy/AiObjectContext.h | 3 + src/strategy/CustomStrategy.cpp | 2 +- src/strategy/actions/ActionContext.h | 4 +- .../actions/BattleGroundJoinAction.cpp | 6 +- src/strategy/actions/BattleGroundTactics.cpp | 2 +- src/strategy/actions/ChatActionContext.h | 2 +- .../actions/WorldPacketActionContext.h | 2 +- src/strategy/values/SharedValueContext.h | 1 + 21 files changed, 91 insertions(+), 78 deletions(-) diff --git a/sql/characters/playerbots_arena_team_names.sql b/sql/characters/playerbots_arena_team_names.sql index dc005d0b..544fdfc1 100644 --- a/sql/characters/playerbots_arena_team_names.sql +++ b/sql/characters/playerbots_arena_team_names.sql @@ -1,14 +1,14 @@ -DROP TABLE IF EXISTS `playerbot_arena_team_names`; -CREATE TABLE `playerbot_arena_team_names` ( - `name_id` mediumint(8) NOT NULL AUTO_INCREMENT UNIQUE, - `name` varchar(24) NOT NULL UNIQUE, - `type` TINYINT(3) NOT NULL, - PRIMARY KEY (`name_id`) +DROP TABLE IF EXISTS `playerbots_arena_team_names`; +CREATE TABLE `playerbots_arena_team_names` ( + `name_id` mediumint(8) NOT NULL AUTO_INCREMENT UNIQUE, + `name` varchar(24) NOT NULL UNIQUE, + `type` TINYINT(3) NOT NULL, + PRIMARY KEY (`name_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Playerbot arena team names'; -DELETE FROM `playerbot_arena_team_names`; -INSERT INTO `playerbot_arena_team_names` (`name_id`,`name`, `type`) VALUES +DELETE FROM `playerbots_arena_team_names`; +INSERT INTO `playerbots_arena_team_names` (`name_id`,`name`, `type`) VALUES (NULL, 'out of coverage',2), (NULL, 'Dead or Alive',2), (NULL, 'Noßrain',2), diff --git a/sql/characters/playerbots_guild_names.sql b/sql/characters/playerbots_guild_names.sql index 7faf9247..324ed5a2 100644 --- a/sql/characters/playerbots_guild_names.sql +++ b/sql/characters/playerbots_guild_names.sql @@ -1,11 +1,11 @@ -DROP TABLE IF EXISTS `playerbot_guild_names`; -CREATE TABLE `playerbot_guild_names` ( - `name_id` INT(11) NOT NULL AUTO_INCREMENT UNIQUE, - `name` varchar(24) NOT NULL UNIQUE, - PRIMARY KEY (`name_id`) +DROP TABLE IF EXISTS `playerbots_guild_names`; +CREATE TABLE `playerbots_guild_names` ( + `name_id` INT(11) NOT NULL AUTO_INCREMENT UNIQUE, + `name` varchar(24) NOT NULL UNIQUE, + PRIMARY KEY (`name_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Playerbot guild names'; -INSERT INTO `playerbot_guild_names` VALUES +INSERT INTO `playerbots_guild_names` VALUES (NULL, 'Black Guard'), (NULL, 'Abyssal Kingdoms'), (NULL, 'Acid Evil'), diff --git a/sql/characters/playerbots_names.sql b/sql/characters/playerbots_names.sql index f9698833..28160a3f 100644 --- a/sql/characters/playerbots_names.sql +++ b/sql/characters/playerbots_names.sql @@ -1,12 +1,12 @@ -DROP TABLE IF EXISTS `playerbot_names`; -CREATE TABLE `playerbot_names` ( +DROP TABLE IF EXISTS `playerbots_names`; +CREATE TABLE `playerbots_names` ( `name_id` INT(11) NOT NULL UNIQUE, `name` varchar(255) NOT NULL, `gender` tinyint(3) unsigned NOT NULL, PRIMARY KEY (`name_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='Playerbot RandomBot names'; -INSERT INTO `playerbot_names` VALUES +INSERT INTO `playerbots_names` VALUES (1,'Aalart',0), (2,'Aalef',0), (3,'Aalot',0), @@ -10687,5 +10687,5 @@ INSERT INTO `playerbot_names` VALUES (10678,'Zuzene',1), (10679,'Zwaante',1); -DELETE FROM `playerbot_names` WHERE LENGTH(`name`) > 12; -ALTER TABLE `playerbot_names` MODIFY `name` varchar(12); +DELETE FROM `playerbots_names` WHERE LENGTH(`name`) > 12; +ALTER TABLE `playerbots_names` MODIFY `name` varchar(12); diff --git a/sql/playerbots/base/playerbots_item_info_cache.sql b/sql/playerbots/base/playerbots_item_info_cache.sql index 5bb467de..d8215829 100644 --- a/sql/playerbots/base/playerbots_item_info_cache.sql +++ b/sql/playerbots/base/playerbots_item_info_cache.sql @@ -1,45 +1,48 @@ DROP TABLE IF EXISTS `playerbots_item_info_cache`; -CREATE TABLE IF NOT EXISTS `playerbots_item_info_cache` ( - `id` int(11) NOT NULL, - `quality` int(11) DEFAULT NULL, - `slot` int(11) DEFAULT NULL, - `source` mediumint(8) DEFAULT NULL, - `sourceId` mediumint(8) DEFAULT NULL, - `team` mediumint(8) DEFAULT NULL, - `faction` mediumint(8) DEFAULT NULL, - `factionRepRank` mediumint(8) DEFAULT NULL, - `minLevel` mediumint(8) DEFAULT NULL, - `scale_1` mediumint(8) DEFAULT NULL, - `scale_2` mediumint(8) DEFAULT NULL, - `scale_3` mediumint(8) DEFAULT NULL, - `scale_4` mediumint(8) DEFAULT NULL, - `scale_5` mediumint(8) DEFAULT NULL, - `scale_6` mediumint(8) DEFAULT NULL, - `scale_7` mediumint(8) DEFAULT NULL, - `scale_8` mediumint(8) DEFAULT NULL, - `scale_9` mediumint(8) DEFAULT NULL, - `scale_10` mediumint(8) DEFAULT NULL, - `scale_11` mediumint(8) DEFAULT NULL, - `scale_12` mediumint(8) DEFAULT NULL, - `scale_13` mediumint(8) DEFAULT NULL, - `scale_14` mediumint(8) DEFAULT NULL, - `scale_15` mediumint(8) DEFAULT NULL, - `scale_16` mediumint(8) DEFAULT NULL, - `scale_17` mediumint(8) DEFAULT NULL, - `scale_18` mediumint(8) DEFAULT NULL, - `scale_19` mediumint(8) DEFAULT NULL, - `scale_20` mediumint(8) DEFAULT NULL, - `scale_21` mediumint(8) DEFAULT NULL, - `scale_22` mediumint(8) DEFAULT NULL, - `scale_23` mediumint(8) DEFAULT NULL, - `scale_24` mediumint(8) DEFAULT NULL, - `scale_25` mediumint(8) DEFAULT NULL, - `scale_26` mediumint(8) DEFAULT NULL, - `scale_27` mediumint(8) DEFAULT NULL, - `scale_28` mediumint(8) DEFAULT NULL, - `scale_29` mediumint(8) DEFAULT NULL, - `scale_30` mediumint(8) DEFAULT NULL, - `scale_31` mediumint(8) DEFAULT NULL, - `scale_32` mediumint(8) DEFAULT NULL, - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED COMMENT='PlayerbotAI item info Cache'; \ No newline at end of file +CREATE TABLE IF NOT EXISTS `playerbots_item_info_cache` +( + `id` int(11) NOT NULL, + `quality` int(11) DEFAULT NULL, + `slot` int(11) DEFAULT NULL, + `source` bigint(20) DEFAULT NULL, + `sourceId` bigint(20) DEFAULT NULL, + `team` bigint(20) DEFAULT NULL, + `faction` bigint(20) DEFAULT NULL, + `factionRepRank` bigint(20) DEFAULT NULL, + `minLevel` bigint(20) DEFAULT NULL, + `scale_1` bigint(20) DEFAULT NULL, + `scale_2` bigint(20) DEFAULT NULL, + `scale_3` bigint(20) DEFAULT NULL, + `scale_4` bigint(20) DEFAULT NULL, + `scale_5` bigint(20) DEFAULT NULL, + `scale_6` bigint(20) DEFAULT NULL, + `scale_7` bigint(20) DEFAULT NULL, + `scale_8` bigint(20) DEFAULT NULL, + `scale_9` bigint(20) DEFAULT NULL, + `scale_10` bigint(20) DEFAULT NULL, + `scale_11` bigint(20) DEFAULT NULL, + `scale_12` bigint(20) DEFAULT NULL, + `scale_13` bigint(20) DEFAULT NULL, + `scale_14` bigint(20) DEFAULT NULL, + `scale_15` bigint(20) DEFAULT NULL, + `scale_16` bigint(20) DEFAULT NULL, + `scale_17` bigint(20) DEFAULT NULL, + `scale_18` bigint(20) DEFAULT NULL, + `scale_19` bigint(20) DEFAULT NULL, + `scale_20` bigint(20) DEFAULT NULL, + `scale_21` bigint(20) DEFAULT NULL, + `scale_22` bigint(20) DEFAULT NULL, + `scale_23` bigint(20) DEFAULT NULL, + `scale_24` bigint(20) DEFAULT NULL, + `scale_25` bigint(20) DEFAULT NULL, + `scale_26` bigint(20) DEFAULT NULL, + `scale_27` bigint(20) DEFAULT NULL, + `scale_28` bigint(20) DEFAULT NULL, + `scale_29` bigint(20) DEFAULT NULL, + `scale_30` bigint(20) DEFAULT NULL, + `scale_31` bigint(20) DEFAULT NULL, + `scale_32` bigint(20) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE = MyISAM + DEFAULT CHARSET = utf8 + ROW_FORMAT = FIXED COMMENT ='PlayerbotAI item info Cache'; \ No newline at end of file diff --git a/sql/world/world_charsections_dbc.sql b/sql/world/world_charsections_dbc.sql index e35d3c7c..99db7fda 100644 --- a/sql/world/world_charsections_dbc.sql +++ b/sql/world/world_charsections_dbc.sql @@ -11,4 +11,4 @@ CREATE TABLE `charsections_dbc` ( `Type` INT NOT NULL DEFAULT '0', `Color` INT NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) USING BTREE -) ENGINE=MYISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC; +) ENGINE=MYISAM DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; diff --git a/sql/world/world_emotetextsound_dbc.sql b/sql/world/world_emotetextsound_dbc.sql index f3a97cd9..88c74f77 100644 --- a/sql/world/world_emotetextsound_dbc.sql +++ b/sql/world/world_emotetextsound_dbc.sql @@ -6,4 +6,4 @@ CREATE TABLE `emotetextsound_dbc` ( `SexId` INT NOT NULL DEFAULT '0', `SoundId` INT NOT NULL DEFAULT '0', PRIMARY KEY (`Id`) USING BTREE -) ENGINE=MYISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=DYNAMIC; +) ENGINE=MYISAM DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC; diff --git a/src/Helpers.h b/src/Helpers.h index d7f385ac..97314718 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -13,6 +13,8 @@ #include #include #include +#include +#include void split(std::vector& dest, std::string const str, char const* delim) { diff --git a/src/PlayerbotAI.cpp b/src/PlayerbotAI.cpp index 6d2b6975..396f1228 100644 --- a/src/PlayerbotAI.cpp +++ b/src/PlayerbotAI.cpp @@ -1259,7 +1259,7 @@ bool PlayerbotAI::TellMasterNoFacing(std::string const text, PlayerbotSecurityLe type = currentChat.first; WorldPacket data; - ChatHandler::BuildChatPacket(data, type == CHAT_MSG_ADDON ? CHAT_MSG_PARTY : type, type == CHAT_MSG_ADDON ? LANG_ADDON : LANG_UNIVERSAL, nullptr, bot, text.c_str()); + ChatHandler::BuildChatPacket(data, type == CHAT_MSG_ADDON ? CHAT_MSG_PARTY : type, type == CHAT_MSG_ADDON ? LANG_ADDON : LANG_UNIVERSAL, bot, nullptr, text.c_str()); master->SendDirectMessage(&data); } diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 30825ed6..81d94973 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -7,7 +7,7 @@ #include "Common.h" #include "SharedDefines.h" -#include "TalentSpec.h" +#include "Talentspec.h" #include diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 3eab06dd..4d1a8b83 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -2350,7 +2350,9 @@ void PlayerbotFactory::InitInventoryTrade() break; case ITEM_QUALITY_UNCOMMON: stacks = 1; - count = urand(1, proto->GetMaxStackSize() / 2); + int maxStackSize = proto->GetMaxStackSize()/2; + uint32 max = std::max(1, maxStackSize); + count = urand(1, max); break; } diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index fdfda566..017aa214 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -6,6 +6,7 @@ #include "Playerbots.h" #include "PlayerbotDbStore.h" #include "PlayerbotFactory.h" +#include "WorldSession.h" PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) { diff --git a/src/RandomItemMgr.cpp b/src/RandomItemMgr.cpp index 819b09de..c296dae3 100644 --- a/src/RandomItemMgr.cpp +++ b/src/RandomItemMgr.cpp @@ -2108,7 +2108,7 @@ void RandomItemMgr::BuildEquipCache() stmt->SetData(1, level); stmt->SetData(2, slot); stmt->SetData(3, quality); - stmt->SetData(4, quality); + stmt->SetData(4, proto->ItemId); PlayerbotsDatabase.Execute(stmt); } diff --git a/src/RandomPlayerbotFactory.h b/src/RandomPlayerbotFactory.h index b55a571c..d6a69eba 100644 --- a/src/RandomPlayerbotFactory.h +++ b/src/RandomPlayerbotFactory.h @@ -9,6 +9,7 @@ #include #include +#include class Player; class WorldSession; diff --git a/src/strategy/AiObjectContext.h b/src/strategy/AiObjectContext.h index cea22c24..62db2265 100644 --- a/src/strategy/AiObjectContext.h +++ b/src/strategy/AiObjectContext.h @@ -12,6 +12,9 @@ #include "Trigger.h" #include "Value.h" +#include +#include + class PlayerbotAI; class AiObjectContext : public PlayerbotAIAware diff --git a/src/strategy/CustomStrategy.cpp b/src/strategy/CustomStrategy.cpp index 85dff252..95df928c 100644 --- a/src/strategy/CustomStrategy.cpp +++ b/src/strategy/CustomStrategy.cpp @@ -97,7 +97,7 @@ void CustomStrategy::LoadActionLines(uint32 owner) do { Field* fields = result->Fetch(); - std::string const action = fields[0].Get(); + std::string const action = fields[1].Get(); actionLines.push_back(action); } while (result->NextRow()); diff --git a/src/strategy/actions/ActionContext.h b/src/strategy/actions/ActionContext.h index 4c1119b1..e4f42bbb 100644 --- a/src/strategy/actions/ActionContext.h +++ b/src/strategy/actions/ActionContext.h @@ -8,8 +8,8 @@ #include "AddLootAction.h" #include "AttackAction.h" #include "AutoLearnSpellAction.h" -#include "BattlegroundTactics.h" -#include "BattlegroundJoinAction.h" +#include "BattleGroundTactics.h" +#include "BattleGroundJoinAction.h" #include "BuyAction.h" #include "CastCustomSpellAction.h" #include "ChangeStrategyAction.h" diff --git a/src/strategy/actions/BattleGroundJoinAction.cpp b/src/strategy/actions/BattleGroundJoinAction.cpp index 69264356..2840f913 100644 --- a/src/strategy/actions/BattleGroundJoinAction.cpp +++ b/src/strategy/actions/BattleGroundJoinAction.cpp @@ -2,7 +2,7 @@ * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. */ -#include "BattlegroundJoinAction.h" +#include "BattleGroundJoinAction.h" #include "ArenaTeam.h" #include "ArenaTeamMgr.h" #include "BattlegroundMgr.h" @@ -939,7 +939,7 @@ bool BGStatusAction::Execute(Event event) { if (ginfo.IsInvitedToBGInstanceGUID && !bot->InBattleground()) { - Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID); + Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId); if (bg) { if (isArena) @@ -1038,7 +1038,7 @@ bool BGStatusAction::Execute(Event event) if (ginfo.IsInvitedToBGInstanceGUID) { - Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID); + Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, _bgTypeId); if (!bg) { LOG_ERROR("playerbots", "Bot {} {}:{} <{}>: Missing QueueInfo for {} {}", diff --git a/src/strategy/actions/BattleGroundTactics.cpp b/src/strategy/actions/BattleGroundTactics.cpp index 29305163..7b371ff0 100644 --- a/src/strategy/actions/BattleGroundTactics.cpp +++ b/src/strategy/actions/BattleGroundTactics.cpp @@ -2,7 +2,7 @@ * Copyright (C) 2016+ AzerothCore , released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version. */ -#include "BattlegroundTactics.h" +#include "BattleGroundTactics.h" #include "ArenaTeam.h" #include "ArenaTeamMgr.h" #include "BattlegroundMgr.h" diff --git a/src/strategy/actions/ChatActionContext.h b/src/strategy/actions/ChatActionContext.h index d64ed813..37a4d7de 100644 --- a/src/strategy/actions/ChatActionContext.h +++ b/src/strategy/actions/ChatActionContext.h @@ -46,7 +46,7 @@ #include "ReviveFromCorpseAction.h" #include "RewardAction.h" #include "RtiAction.h" -#include "RTSCAction.h" +#include "RtscAction.h" #include "SaveManaAction.h" #include "SellAction.h" #include "SetCraftAction.h" diff --git a/src/strategy/actions/WorldPacketActionContext.h b/src/strategy/actions/WorldPacketActionContext.h index 80159cdb..a6cd931b 100644 --- a/src/strategy/actions/WorldPacketActionContext.h +++ b/src/strategy/actions/WorldPacketActionContext.h @@ -12,7 +12,7 @@ #include "AcceptResurrectAction.h" #include "AreaTriggerAction.h" #include "ArenaTeamActions.h" -#include "BattlegroundTactics.h" +#include "BattleGroundTactics.h" #include "CheckMountStateAction.h" #include "GuildAcceptAction.h" #include "GuildCreateActions.h" diff --git a/src/strategy/values/SharedValueContext.h b/src/strategy/values/SharedValueContext.h index 84934469..72ceca85 100644 --- a/src/strategy/values/SharedValueContext.h +++ b/src/strategy/values/SharedValueContext.h @@ -9,6 +9,7 @@ #include "LootValues.h" #include "PvpValues.h" #include "QuestValues.h" +#include "Playerbots.h" class PlayerbotAI;