mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
code re-use
This commit is contained in:
parent
a10ffd8dfa
commit
df6f6bafc6
|
@ -55,8 +55,7 @@ void CPlayer::Reset()
|
|||
|
||||
m_LastCommandPos = 0;
|
||||
m_LastPlaytime = 0;
|
||||
m_Sent1stAfkWarning = false;
|
||||
m_Sent2ndAfkWarning = false;
|
||||
mem_zero(m_SentAfkWarning, sizeof(m_SentAfkWarning));
|
||||
m_ChatScore = 0;
|
||||
m_Moderating = false;
|
||||
m_EyeEmoteEnabled = true;
|
||||
|
@ -699,7 +698,7 @@ void CPlayer::TryRespawn()
|
|||
m_pCharacter->SetSolo(true);
|
||||
}
|
||||
|
||||
bool CPlayer::AfkTimer(CNetObj_PlayerInput *NewTarget)
|
||||
bool CPlayer::AfkTimer(CNetObj_PlayerInput *pNewTarget)
|
||||
{
|
||||
/*
|
||||
afk timer (x, y = mouse coordinates)
|
||||
|
@ -715,42 +714,38 @@ bool CPlayer::AfkTimer(CNetObj_PlayerInput *NewTarget)
|
|||
if(g_Config.m_SvMaxAfkTime == 0)
|
||||
return false; // 0 = disabled
|
||||
|
||||
if(NewTarget->m_TargetX != m_pLastTarget->m_TargetX || NewTarget->m_TargetY != m_pLastTarget->m_TargetY)
|
||||
if(pNewTarget->m_TargetX != m_pLastTarget->m_TargetX || pNewTarget->m_TargetY != m_pLastTarget->m_TargetY)
|
||||
{
|
||||
UpdatePlaytime();
|
||||
// we shouldn't update m_pLastTarget here
|
||||
m_Sent1stAfkWarning = false; // afk timer's 1st warning after 50% of sv_max_afk_time
|
||||
m_Sent2ndAfkWarning = false;
|
||||
mem_zero(m_SentAfkWarning, sizeof(m_SentAfkWarning)); // resetting warnings
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_Paused)
|
||||
{
|
||||
char AfkMsg[160];
|
||||
// not playing, check how long
|
||||
if(!m_Sent1stAfkWarning && m_LastPlaytime < time_get() - time_freq() * (int)(g_Config.m_SvMaxAfkTime * 0.5))
|
||||
{
|
||||
str_format(AfkMsg, sizeof(AfkMsg),
|
||||
"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
|
||||
(int)(g_Config.m_SvMaxAfkTime * 0.5),
|
||||
g_Config.m_SvMaxAfkTime);
|
||||
m_pGameServer->SendChatTarget(m_ClientID, AfkMsg);
|
||||
m_Sent1stAfkWarning = true;
|
||||
}
|
||||
else if(!m_Sent2ndAfkWarning && m_LastPlaytime < time_get() - time_freq() * (int)(g_Config.m_SvMaxAfkTime * 0.9))
|
||||
{
|
||||
str_format(AfkMsg, sizeof(AfkMsg),
|
||||
"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
|
||||
(int)(g_Config.m_SvMaxAfkTime * 0.9),
|
||||
g_Config.m_SvMaxAfkTime);
|
||||
m_pGameServer->SendChatTarget(m_ClientID, AfkMsg);
|
||||
m_Sent2ndAfkWarning = true;
|
||||
}
|
||||
else if(m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkTime)
|
||||
// kick if player stays afk too long
|
||||
if(m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkTime)
|
||||
{
|
||||
m_pGameServer->Server()->Kick(m_ClientID, "Away from keyboard");
|
||||
return true;
|
||||
}
|
||||
// not playing, check how long
|
||||
for(int i = 0; i < 2; i++)
|
||||
{
|
||||
int AfkTime = (int)(g_Config.m_SvMaxAfkTime * (i == 0 ? 0.5 : 0.9));
|
||||
if(!m_SentAfkWarning[i] && m_LastPlaytime < time_get() - time_freq() * AfkTime)
|
||||
{
|
||||
char aAfkMsg[160];
|
||||
str_format(aAfkMsg, sizeof(aAfkMsg),
|
||||
"You have been afk for %d seconds now. Please note that you get kicked after not playing for %d seconds.",
|
||||
AfkTime,
|
||||
g_Config.m_SvMaxAfkTime);
|
||||
m_pGameServer->SendChatTarget(m_ClientID, aAfkMsg);
|
||||
m_SentAfkWarning[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -177,16 +177,22 @@ public:
|
|||
|
||||
bool m_Moderating;
|
||||
|
||||
bool AfkTimer(CNetObj_PlayerInput *NewTarget); //returns true if kicked
|
||||
bool AfkTimer(CNetObj_PlayerInput *pNewTarget); // returns true if kicked
|
||||
void UpdatePlaytime();
|
||||
void AfkVoteTimer(CNetObj_PlayerInput *NewTarget);
|
||||
void AfkVoteTimer(CNetObj_PlayerInput *pNewTarget);
|
||||
int64_t m_LastPlaytime;
|
||||
int64_t m_LastEyeEmote;
|
||||
int64_t m_LastBroadcast;
|
||||
bool m_LastBroadcastImportance;
|
||||
|
||||
CNetObj_PlayerInput *m_pLastTarget;
|
||||
bool m_Sent1stAfkWarning; // afk timer's 1st warning after 50% of sv_max_afk_time
|
||||
bool m_Sent2ndAfkWarning; // afk timer's 2nd warning after 90% of sv_max_afk_time
|
||||
/*
|
||||
afk timer's 1st warning after 50% of sv_max_afk_time
|
||||
2nd warning after 90%
|
||||
kick after reaching 100% of sv_max_afk_time
|
||||
*/
|
||||
bool m_SentAfkWarning[2];
|
||||
|
||||
bool m_EyeEmoteEnabled;
|
||||
int m_TimerType;
|
||||
|
||||
|
|
Loading…
Reference in a new issue