Skip to content

Commit

Permalink
Player: Add afk kick after 15 minutes back in
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Feb 25, 2024
1 parent 4320a68 commit ea5fd3b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/game/Entities/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1871,6 +1871,8 @@ void Player::ToggleAFK()
// afk player not allowed in battleground
if (isAFK() && InBattleGround() && !InArena() && !IsGameMaster())
LeaveBattleground();

GetSession()->AfkStateChange(isAFK());
}

void Player::ToggleDND()
Expand Down
19 changes: 16 additions & 3 deletions src/game/Server/WorldSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ WorldSession::WorldSession(uint32 id, WorldSocket* sock, AccountTypes sec, uint8
_player(nullptr), m_socket(sock ? sock->shared_from_this() : nullptr), m_requestSocket(nullptr), m_localAddress("127.0.0.1"), m_sessionState(WORLD_SESSION_STATE_CREATED),
_security(sec), _accountId(id), m_expansion(expansion), m_accountName(accountName), m_accountFlags(accountFlags),
m_clientOS(CLIENT_OS_UNKNOWN), m_clientPlatform(CLIENT_PLATFORM_UNKNOWN), m_gameBuild(0), m_accountMaxLevel(0), m_orderCounter(0), m_lastAnticheatUpdate(0), m_anticheat(nullptr),
_logoutTime(0), m_playerSave(true), m_inQueue(false), m_playerLoading(false), m_kickSession(false), m_playerLogout(false), m_playerRecentlyLogout(false),
_logoutTime(0), m_afkTime(0), m_playerSave(true), m_inQueue(false), m_playerLoading(false), m_kickSession(false), m_playerLogout(false), m_playerRecentlyLogout(false),
m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(sObjectMgr.GetStorageLocaleIndexFor(locale)),
m_latency(0), m_tutorialState(TUTORIALDATA_UNCHANGED),
m_timeSyncClockDeltaQueue(6), m_timeSyncClockDelta(0), m_pendingTimeSyncRequests(), m_timeSyncNextCounter(0), m_timeSyncTimer(0),
Expand Down Expand Up @@ -532,8 +532,12 @@ bool WorldSession::Update(uint32 /*diff*/)
// give the opportunity for this player to reconnect within 20 sec
SetOffline();
}
else if (ShouldLogOut(time(nullptr)) && !m_playerLoading) // check if delayed logout is fired
LogoutPlayer();
else if (!m_playerLoading)
{
time_t curTime = time(nullptr);
if (ShouldAfkDisconnect(curTime) || ShouldLogOut(curTime)) // check if delayed logout or afk is fired
LogoutPlayer();
}

return true;
}
Expand Down Expand Up @@ -769,6 +773,7 @@ void WorldSession::LogoutPlayer()
SetInCharSelection();

_logoutTime = 0;
m_afkTime = 0;

if (m_kickSession)
{
Expand Down Expand Up @@ -1296,6 +1301,14 @@ void WorldSession::SetNoAnticheat()

#endif

void WorldSession::AfkStateChange(bool state)
{
if (state)
m_afkTime = time(nullptr);
else
m_afkTime = 0;
}

void WorldSession::HandleWardenDataOpcode(WorldPacket& recv_data)
{
m_anticheat->WardenPacket(recv_data);
Expand Down
8 changes: 8 additions & 0 deletions src/game/Server/WorldSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ class WorldSession
m_kickSession = kickSession;
}

void AfkStateChange(bool state);

/// Is logout cooldown expired?
bool ShouldLogOut(time_t currTime) const
{
Expand All @@ -314,6 +316,11 @@ class WorldSession
return (_logoutTime > 0 && currTime >= _logoutTime + 60);
}

bool ShouldAfkDisconnect(time_t currTime) const
{
return (m_afkTime > 0 && currTime >= m_afkTime + 15 * MINUTE);
}

void LogoutPlayer();
void KickPlayer(bool save = false, bool inPlace = false); // inplace variable needed for shutdown

Expand Down Expand Up @@ -952,6 +959,7 @@ class WorldSession

time_t _logoutTime; // when logout will be processed after a logout request
time_t m_kickTime;
time_t m_afkTime;
bool m_playerSave; // should we have to save the player after logout request
bool m_inQueue; // session wait in auth.queue
bool m_playerLoading; // code processed in LoginPlayer
Expand Down

0 comments on commit ea5fd3b

Please sign in to comment.