mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-13 00:58:33 +00:00
Add secure login handling for playerbots (#1953)
Introduces PlayerbotsSecureLoginServerScript to handle secure login scenarios for playerbots. Ensures that if a playerbot is already online when a login is attempted, it is properly logged out before allowing the new session. Registers the new script in the Playerbots initialization.
This commit is contained in:
@@ -502,6 +502,8 @@ public:
|
|||||||
void OnBattlegroundEnd(Battleground* bg, TeamId /*winnerTeam*/) override { bgStrategies.erase(bg->GetInstanceID()); }
|
void OnBattlegroundEnd(Battleground* bg, TeamId /*winnerTeam*/) override { bgStrategies.erase(bg->GetInstanceID()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void AddPlayerbotsSecureLoginScripts();
|
||||||
|
|
||||||
void AddPlayerbotsScripts()
|
void AddPlayerbotsScripts()
|
||||||
{
|
{
|
||||||
new PlayerbotsDatabaseScript();
|
new PlayerbotsDatabaseScript();
|
||||||
@@ -511,6 +513,7 @@ void AddPlayerbotsScripts()
|
|||||||
new PlayerbotsWorldScript();
|
new PlayerbotsWorldScript();
|
||||||
new PlayerbotsScript();
|
new PlayerbotsScript();
|
||||||
new PlayerBotsBGScript();
|
new PlayerBotsBGScript();
|
||||||
|
AddPlayerbotsSecureLoginScripts();
|
||||||
|
|
||||||
AddSC_playerbots_commandscript();
|
AddSC_playerbots_commandscript();
|
||||||
}
|
}
|
||||||
|
|||||||
82
src/PlayerbotsSecureLogin.cpp
Normal file
82
src/PlayerbotsSecureLogin.cpp
Normal file
@@ -0,0 +1,82 @@
|
|||||||
|
#include "ScriptMgr.h"
|
||||||
|
#include "Opcodes.h"
|
||||||
|
#include "Player.h"
|
||||||
|
#include "ObjectAccessor.h"
|
||||||
|
|
||||||
|
#include "Playerbots.h"
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
static Player* FindOnlineAltbotByGuid(ObjectGuid guid)
|
||||||
|
{
|
||||||
|
if (!guid)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
Player* p = ObjectAccessor::FindPlayer(guid);
|
||||||
|
if (!p)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
PlayerbotAI* ai = GET_PLAYERBOT_AI(p);
|
||||||
|
if (!ai || ai->IsRealPlayer())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ForceLogoutViaPlayerbotHolder(Player* target)
|
||||||
|
{
|
||||||
|
if (!target)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PlayerbotAI* ai = GET_PLAYERBOT_AI(target);
|
||||||
|
if (!ai)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (Player* master = ai->GetMaster())
|
||||||
|
{
|
||||||
|
if (PlayerbotMgr* mgr = GET_PLAYERBOT_MGR(master))
|
||||||
|
{
|
||||||
|
mgr->LogoutPlayerBot(target->GetGUID());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sRandomPlayerbotMgr)
|
||||||
|
{
|
||||||
|
sRandomPlayerbotMgr->LogoutPlayerBot(target->GetGUID());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlayerbotsSecureLoginServerScript : public ServerScript
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PlayerbotsSecureLoginServerScript()
|
||||||
|
: ServerScript("PlayerbotsSecureLoginServerScript", { SERVERHOOK_CAN_PACKET_RECEIVE }) {}
|
||||||
|
|
||||||
|
bool CanPacketReceive(WorldSession* /*session*/, WorldPacket& packet) override
|
||||||
|
{
|
||||||
|
if (packet.GetOpcode() != CMSG_PLAYER_LOGIN)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
auto const oldPos = packet.rpos();
|
||||||
|
ObjectGuid loginGuid;
|
||||||
|
packet >> loginGuid;
|
||||||
|
packet.rpos(oldPos);
|
||||||
|
|
||||||
|
if (!loginGuid)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Player* existingAltbot = FindOnlineAltbotByGuid(loginGuid);
|
||||||
|
if (existingAltbot)
|
||||||
|
ForceLogoutViaPlayerbotHolder(existingAltbot);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void AddPlayerbotsSecureLoginScripts()
|
||||||
|
{
|
||||||
|
new PlayerbotsSecureLoginServerScript();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user