From 0e15c22639f8914bc0a627207ee04fa3b32baac3 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 21 Feb 2014 18:27:00 +0100 Subject: [PATCH] More sensitive afk detection --- src/game/server/player.cpp | 15 ++++++--------- src/game/server/player.h | 3 ++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 3282210dd..984861409 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -42,8 +42,6 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team) m_LastCommandPos = 0; m_LastPlaytime = time_get(); - m_LastTarget_x = 0; - m_LastTarget_y = 0; m_Sent1stAfkWarning = 0; m_Sent2ndAfkWarning = 0; m_ChatScore = 0; @@ -312,6 +310,8 @@ void CPlayer::OnPredictedInput(CNetObj_PlayerInput *NewInput) if((m_PlayerFlags&PLAYERFLAG_CHATTING) && (NewInput->m_PlayerFlags&PLAYERFLAG_CHATTING)) return; + AfkVoteTimer(NewInput); + if(m_pCharacter && !m_Paused) m_pCharacter->OnPredictedInput(NewInput); } @@ -320,7 +320,7 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput) { if (AfkTimer(NewInput->m_TargetX, NewInput->m_TargetY)) return; // we must return if kicked, as player struct is already deleted - AfkVoteTimer(NewInput->m_TargetX, NewInput->m_TargetY); + AfkVoteTimer(NewInput); if(NewInput->m_PlayerFlags&PLAYERFLAG_CHATTING) { @@ -525,18 +525,15 @@ bool CPlayer::AfkTimer(int NewTargetX, int NewTargetY) return false; } -void CPlayer::AfkVoteTimer(int NewTargetX, int NewTargetY) +void CPlayer::AfkVoteTimer(CNetObj_PlayerInput *NewTarget) { if(g_Config.m_SvMaxAfkVoteTime == 0) return; - if(NewTargetX != m_LastTarget_x || NewTargetY != m_LastTarget_y) + if(mem_comp(NewTarget, &m_LastTarget, sizeof(CNetObj_PlayerInput)) != 0) { m_LastPlaytime = time_get(); - m_LastTarget_x = NewTargetX; - m_LastTarget_y = NewTargetY; - m_Sent1stAfkWarning = 0; // afk timer's 1st warning after 50% of sv_max_afk_time - m_Sent2ndAfkWarning = 0; + mem_copy(&m_LastTarget, NewTarget, sizeof(CNetObj_PlayerInput)); } else if(m_LastPlaytime < time_get()-time_freq()*g_Config.m_SvMaxAfkVoteTime) { diff --git a/src/game/server/player.h b/src/game/server/player.h index 86305f9de..f6268bb25 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -146,11 +146,12 @@ public: int m_ChatScore; bool AfkTimer(int new_target_x, int new_target_y); //returns true if kicked - void AfkVoteTimer(int new_target_x, int new_target_y); + void AfkVoteTimer(CNetObj_PlayerInput *NewTarget); int64 m_LastPlaytime; int64 m_LastEyeEmote; int m_LastTarget_x; int m_LastTarget_y; + CNetObj_PlayerInput m_LastTarget; int m_Sent1stAfkWarning; // afk timer's 1st warning after 50% of sv_max_afk_time int m_Sent2ndAfkWarning; // afk timer's 2nd warning after 90% of sv_max_afk_time char m_pAfkMsg[160];