Skip to content

Commit a4d2c83

Browse files
authored
Merge pull request mod-playerbots#2330 from mod-playerbots/test-staging
Revert "Feat: Reintroduce timed logouts" (mod-playerbots#2329)
2 parents e87bca1 + a4b37c9 commit a4d2c83

2 files changed

Lines changed: 51 additions & 68 deletions

File tree

src/Bot/PlayerbotAI.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -243,22 +243,10 @@ void PlayerbotAI::UpdateAI(uint32 elapsed, bool minimal)
243243
nextAICheckDelay = 0;
244244

245245
// Early return if bot is in invalid state
246-
if (!bot || !bot->GetSession() || !bot->IsInWorld() || bot->IsBeingTeleported() || bot->IsDuringRemoveFromWorld())
246+
if (!bot || !bot->GetSession() || !bot->IsInWorld() || bot->IsBeingTeleported() ||
247+
bot->GetSession()->isLogingOut() || bot->IsDuringRemoveFromWorld())
247248
return;
248249

249-
// During timed logout countdown, cancel if bot enters combat (this cancellation is handled client-side for real players).
250-
if (bot->GetSession()->isLogingOut())
251-
{
252-
bool canLogoutInCombat = bot->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
253-
if (bot->IsInCombat() && !canLogoutInCombat)
254-
{
255-
WorldPackets::Character::LogoutCancel cancelData = WorldPacket(CMSG_LOGOUT_CANCEL);
256-
bot->GetSession()->HandleLogoutCancelOpcode(cancelData);
257-
}
258-
else
259-
return;
260-
}
261-
262250
// Handle cheat options (set bot health and power if cheats are enabled)
263251
if (bot->IsAlive() &&
264252
(static_cast<uint32>(GetCheat()) > 0 || static_cast<uint32>(sPlayerbotAIConfig.botCheatMask) > 0))
@@ -727,9 +715,30 @@ void PlayerbotAI::HandleCommand(uint32 type, const std::string& text, Player& fr
727715
Reset(true);
728716
}
729717

730-
// Commented-out logout commands blocks removed from here and implemented in HandleCommand.
731-
// Remaining is a commented-out action delay command block.
732-
/*
718+
// TODO: missing implementation to port
719+
/*else if (filtered == "logout")
720+
{
721+
if (!(bot->IsStunnedByLogout() || bot->GetSession()->isLogingOut()))
722+
{
723+
if (type == CHAT_MSG_WHISPER)
724+
TellPlayer(&fromPlayer, BOT_TEXT("logout_start"));
725+
726+
if (master && master->GetPlayerbotMgr())
727+
SetShouldLogOut(true);
728+
}
729+
}
730+
else if (filtered == "logout cancel")
731+
{
732+
if (bot->IsStunnedByLogout() || bot->GetSession()->isLogingOut())
733+
{
734+
if (type == CHAT_MSG_WHISPER)
735+
TellPlayer(&fromPlayer, BOT_TEXT("logout_cancel"));
736+
737+
WorldPacket p;
738+
bot->GetSession()->HandleLogoutCancelOpcode(p);
739+
SetShouldLogOut(false);
740+
}
741+
}
733742
else if ((filtered.size() > 5) && (filtered.substr(0, 5) == "wait ") && (filtered.find("wait for attack") ==
734743
std::string::npos))
735744
{
@@ -1075,7 +1084,7 @@ void PlayerbotAI::HandleCommand(uint32 type, std::string const text, Player* fro
10751084
TellMaster(message);
10761085
}
10771086
}
1078-
else if (filtered == "cancel logout" || filtered == "logout cancel")
1087+
else if (filtered == "logout cancel")
10791088
{
10801089
if (!bot->GetSession()->isLogingOut())
10811090
return;
@@ -1091,7 +1100,9 @@ void PlayerbotAI::HandleCommand(uint32 type, std::string const text, Player* fro
10911100
bot->GetSession()->HandleLogoutCancelOpcode(data);
10921101
}
10931102
else
1103+
{
10941104
chatCommands.push_back(ChatCommandHolder(filtered, fromPlayer, type));
1105+
}
10951106
}
10961107

10971108
void PlayerbotAI::HandleBotOutgoingPacket(WorldPacket const& packet)

src/Bot/PlayerbotMgr.cpp

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,6 @@ void PlayerbotHolder::LogoutAllBots()
299299
if (!botAI || botAI->IsRealPlayer())
300300
continue;
301301

302-
// If bot is mid-countdown, cancel the timer so LogoutPlayerBot proceeds immediately.
303-
WorldSession* session = bot->GetSession();
304-
if (session && session->isLogingOut())
305-
session->SetLogoutStartTime(0);
306-
307302
LogoutPlayerBot(bot->GetGUID());
308303
}
309304
}
@@ -366,50 +361,36 @@ void PlayerbotHolder::LogoutPlayerBot(ObjectGuid guid)
366361
WorldSession* botWorldSessionPtr = bot->GetSession();
367362
WorldSession* masterWorldSessionPtr = nullptr;
368363

369-
// If already in timed logout countdown, complete it once the 20-second timer expires.
370364
if (botWorldSessionPtr->isLogingOut())
371-
{
372-
if (botWorldSessionPtr->ShouldLogOut(time(nullptr)))
373-
{
374-
std::string message = PlayerbotTextMgr::instance().GetBotTextOrDefault(
375-
"goodbye", "Goodbye!", {});
376-
botAI->TellMaster(message);
377-
RemoveFromPlayerbotsMap(guid);
378-
botWorldSessionPtr->LogoutPlayer(true);
379-
delete botWorldSessionPtr;
380-
}
381365
return;
382-
}
383366

384367
Player* master = botAI->GetMaster();
385368
if (master)
386369
masterWorldSessionPtr = master->GetSession();
387370

388-
// Instant logout checking:
389-
bool logout =
390-
bot->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ||
391-
bot->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
392-
(masterWorldSessionPtr && !masterWorldSessionPtr->GetPlayer()) ||
393-
// Master's socket is already gone (EXIT GAME -> EXIT NOW is the most typical cause).
394-
// Force instant logout. Without this, the bot restarts its 20-second countdown and fires LogoutPlayer() 20 seconds
395-
// after the master's Player object has been deleted, causing the bot's logout to crash on the now deleted master.
396-
(masterWorldSessionPtr && masterWorldSessionPtr->IsSocketClosed()) ||
397-
(masterWorldSessionPtr && masterWorldSessionPtr->ShouldLogOut(time(nullptr))) ||
398-
// If the bot's master has security clearance for `InstantLogout` in worldserver.conf, so does the bot.
399-
(master &&
400-
(master->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) ||
401-
master->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
402-
(masterWorldSessionPtr &&
403-
masterWorldSessionPtr->GetSecurity() >= (AccountTypes)sWorld->getIntConfig(CONFIG_INSTANT_LOGOUT))));
404-
405-
if (!logout)
406-
{
407-
// Start the 20-second logout countdown. CancelLogout() can interrupt this.
408-
WorldPackets::Character::LogoutRequest data = WorldPacket(CMSG_LOGOUT_REQUEST);
409-
botWorldSessionPtr->HandleLogoutRequestOpcode(data);
410-
return;
411-
}
371+
// TODO: Review whether or not to implement timed logout.
372+
// Unused block. Useful only for timed logout.
373+
/*
374+
// check for instant logout
375+
bool logout = botWorldSessionPtr->ShouldLogOut(time(nullptr));
376+
377+
if (masterWorldSessionPtr && masterWorldSessionPtr->ShouldLogOut(time(nullptr)))
378+
logout = true;
379+
380+
if (masterWorldSessionPtr && !masterWorldSessionPtr->GetPlayer())
381+
logout = true;
382+
383+
if (bot->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || bot->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
384+
botWorldSessionPtr->GetSecurity() >= (AccountTypes)sWorld->getIntConfig(CONFIG_INSTANT_LOGOUT))
385+
logout = true;
412386
387+
if (master &&
388+
(master->HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING) || master->HasUnitState(UNIT_STATE_IN_FLIGHT) ||
389+
(masterWorldSessionPtr &&
390+
masterWorldSessionPtr->GetSecurity() >= (AccountTypes)sWorld->getIntConfig(CONFIG_INSTANT_LOGOUT))))
391+
logout = true;
392+
*/
393+
// Instant logout (the only option right now)
413394
{
414395
std::string message = PlayerbotTextMgr::instance().GetBotTextOrDefault(
415396
"goodbye", "Goodbye!", {});
@@ -1497,15 +1478,6 @@ void PlayerbotMgr::UpdateAIInternal(uint32 elapsed, bool /*minimal*/)
14971478
{
14981479
SetNextCheckDelay(sPlayerbotAIConfig.reactDelay);
14991480
CheckTellErrors(elapsed);
1500-
1501-
// Complete timed logouts for added bots once the 20-second countdown has elapsed.
1502-
std::vector<ObjectGuid> expiredLogouts;
1503-
for (auto const& [botGuid, bot] : playerBots)
1504-
if (bot && bot->GetSession() && bot->GetSession()->ShouldLogOut(time(nullptr)))
1505-
expiredLogouts.push_back(botGuid);
1506-
1507-
for (ObjectGuid const& guid : expiredLogouts)
1508-
LogoutPlayerBot(guid);
15091481
}
15101482

15111483
void PlayerbotMgr::HandleCommand(uint32 type, std::string const text)

0 commit comments

Comments
 (0)