mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-30 00:43:48 +00:00
[Crash fix] Duplicate loading bot
This commit is contained in:
@@ -48,6 +48,10 @@ public:
|
|||||||
|
|
||||||
void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId)
|
void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId)
|
||||||
{
|
{
|
||||||
|
// bot is loading
|
||||||
|
if (botLoading.find(playerGuid) != botLoading.end())
|
||||||
|
return;
|
||||||
|
|
||||||
// has bot already been added?
|
// has bot already been added?
|
||||||
Player* bot = ObjectAccessor::FindConnectedPlayer(playerGuid);
|
Player* bot = ObjectAccessor::FindConnectedPlayer(playerGuid);
|
||||||
if (bot && bot->IsInWorld())
|
if (bot && bot->IsInWorld())
|
||||||
@@ -64,6 +68,8 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
botLoading.insert(playerGuid);
|
||||||
|
|
||||||
if (WorldSession* masterSession = sWorld->FindSession(masterAccountId))
|
if (WorldSession* masterSession = sWorld->FindSession(masterAccountId))
|
||||||
{
|
{
|
||||||
masterSession->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder))
|
masterSession->AddQueryHolderCallback(CharacterDatabase.DelayQueryHolder(holder))
|
||||||
@@ -80,13 +86,6 @@ void PlayerbotHolder::AddPlayerBot(ObjectGuid playerGuid, uint32 masterAccountId
|
|||||||
|
|
||||||
void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder const& holder)
|
void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder const& holder)
|
||||||
{
|
{
|
||||||
// has bot already been added?
|
|
||||||
Player* loginBot = ObjectAccessor::FindConnectedPlayer(holder.GetGuid());
|
|
||||||
if (loginBot && loginBot->IsInWorld())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32 botAccountId = holder.GetAccountId();
|
uint32 botAccountId = holder.GetAccountId();
|
||||||
|
|
||||||
// At login DBC locale should be what the server is set to use by default (as spells etc are hardcoded to ENUS this
|
// At login DBC locale should be what the server is set to use by default (as spells etc are hardcoded to ENUS this
|
||||||
@@ -101,8 +100,7 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
|
|||||||
{
|
{
|
||||||
botSession->LogoutPlayer(true);
|
botSession->LogoutPlayer(true);
|
||||||
delete botSession;
|
delete botSession;
|
||||||
// LOG_ERROR("playerbots", "Error logging in bot {}, please try to reset all random bots",
|
botLoading.erase(holder.GetGuid());
|
||||||
// holder.GetGuid().ToString().c_str());
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,12 +157,8 @@ void PlayerbotHolder::HandlePlayerBotLoginCallback(PlayerbotLoginQueryHolder con
|
|||||||
}
|
}
|
||||||
botSession->LogoutPlayer(true);
|
botSession->LogoutPlayer(true);
|
||||||
delete botSession;
|
delete botSession;
|
||||||
// OnBotLogin(bot);
|
|
||||||
// LogoutPlayerBot(bot->GetGUID());
|
|
||||||
|
|
||||||
// LOG_ERROR("playerbots", "Attempt to add not allowed bot {}, please try to reset all random bots",
|
|
||||||
// bot->GetName());
|
|
||||||
}
|
}
|
||||||
|
botLoading.erase(holder.GetGuid());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayerbotHolder::UpdateSessions()
|
void PlayerbotHolder::UpdateSessions()
|
||||||
@@ -387,7 +381,7 @@ void PlayerbotHolder::DisablePlayerBot(ObjectGuid guid)
|
|||||||
|
|
||||||
LOG_DEBUG("playerbots", "Bot {} logged out", bot->GetName().c_str());
|
LOG_DEBUG("playerbots", "Bot {} logged out", bot->GetName().c_str());
|
||||||
|
|
||||||
bot->SaveToDB(false, false);
|
// bot->SaveToDB(false, false);
|
||||||
|
|
||||||
if (botAI->GetAiObjectContext()) // Maybe some day re-write to delate all pointer values.
|
if (botAI->GetAiObjectContext()) // Maybe some day re-write to delate all pointer values.
|
||||||
{
|
{
|
||||||
@@ -540,7 +534,7 @@ void PlayerbotHolder::OnBotLogin(Player* const bot)
|
|||||||
bot->RemovePlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
|
bot->RemovePlayerFlag(PLAYER_FLAGS_NO_XP_GAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
bot->SaveToDB(false, false);
|
// bot->SaveToDB(false, false);
|
||||||
if (master && isRandomAccount && master->GetLevel() < bot->GetLevel())
|
if (master && isRandomAccount && master->GetLevel() < bot->GetLevel())
|
||||||
{
|
{
|
||||||
// PlayerbotFactory factory(bot, master->GetLevel());
|
// PlayerbotFactory factory(bot, master->GetLevel());
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#define _PLAYERBOT_PLAYERBOTMGR_H
|
#define _PLAYERBOT_PLAYERBOTMGR_H
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "ObjectGuid.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "PlayerbotAIBase.h"
|
#include "PlayerbotAIBase.h"
|
||||||
#include "QueryHolder.h"
|
#include "QueryHolder.h"
|
||||||
@@ -57,6 +58,7 @@ protected:
|
|||||||
virtual void OnBotLoginInternal(Player* const bot) = 0;
|
virtual void OnBotLoginInternal(Player* const bot) = 0;
|
||||||
|
|
||||||
PlayerBotMap playerBots;
|
PlayerBotMap playerBots;
|
||||||
|
std::unordered_set<ObjectGuid> botLoading;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PlayerbotMgr : public PlayerbotHolder
|
class PlayerbotMgr : public PlayerbotHolder
|
||||||
|
|||||||
Reference in New Issue
Block a user