Files
mod-playerbots/src/Script/PlayerbotsSecureLogin.cpp
Keleborn d6f396ab50 CoreUpdate (#2207)
Core PR update.
https://github.com/mod-playerbots/azerothcore-wotlk/pull/178

Core set packet as const, and so had to recast.
2026-03-14 11:50:20 +01:00

81 lines
1.8 KiB
C++

#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;
}
}
sRandomPlayerbotMgr.LogoutPlayerBot(target->GetGUID());
}
}
class PlayerbotsSecureLoginServerScript : public ServerScript
{
public:
PlayerbotsSecureLoginServerScript()
: ServerScript("PlayerbotsSecureLoginServerScript", { SERVERHOOK_CAN_PACKET_RECEIVE }) {}
bool CanPacketReceive(WorldSession* /*session*/, WorldPacket const& packet) override
{
if (packet.GetOpcode() != CMSG_PLAYER_LOGIN)
return true;
WorldPacket& pkt = const_cast<WorldPacket&>(packet);
auto const oldPos = pkt.rpos();
ObjectGuid loginGuid;
pkt >> loginGuid;
pkt.rpos(oldPos);
if (!loginGuid)
return true;
Player* existingAltbot = FindOnlineAltbotByGuid(loginGuid);
if (existingAltbot)
ForceLogoutViaPlayerbotHolder(existingAltbot);
return true;
}
};
void AddPlayerbotsSecureLoginScripts()
{
new PlayerbotsSecureLoginServerScript();
}