diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index bc17bc34..13863ecb 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "ChannelMgr.h" #include "CharacterCache.h" @@ -34,6 +35,34 @@ #include "PlayerbotDbStore.h" #include "WorldSessionMgr.h" +class BotInitGuard +{ +public: + BotInitGuard(ObjectGuid guid) : guid(guid), active(false) + { + if (!botsBeingInitialized.contains(guid)) + { + botsBeingInitialized.insert(guid); + active = true; + } + } + + ~BotInitGuard() + { + if (active) + botsBeingInitialized.erase(guid); + } + + bool IsLocked() const { return !active; } + +private: + ObjectGuid guid; + bool active; + static std::unordered_set botsBeingInitialized; +}; + +std::unordered_set BotInitGuard::botsBeingInitialized; + PlayerbotHolder::PlayerbotHolder() : PlayerbotAIBase(false) {} class PlayerbotLoginQueryHolder : public LoginQueryHolder { @@ -696,6 +725,14 @@ std::string const PlayerbotHolder::ProcessBotCommand(std::string const cmd, Obje { return "The command is not allowed, use init=auto instead."; } + + // Use boot guard + BotInitGuard guard(bot->GetGUID()); + if (guard.IsLocked()) + { + return "Initialization already in progress, please wait."; + } + int gs; if (cmd == "init=white" || cmd == "init=common") {