mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Merge #6178
6178: Persist AFK state of players on map change, fix players always being considered AFK with `sv_max_afk_time 0 ` r=def- a=Robyt3 ## Checklist - [X] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test (especially base/) or added coverage to integration test - [ ] Considered possible null pointers and out of bounds array indexing - [X] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
674b5f919d
|
@ -1028,7 +1028,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID)
|
||||||
AmmoCount = (!m_FreezeTime) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0;
|
AmmoCount = (!m_FreezeTime) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(GetPlayer()->m_Afk || GetPlayer()->IsPaused())
|
if(GetPlayer()->IsAfk() || GetPlayer()->IsPaused())
|
||||||
{
|
{
|
||||||
if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen)
|
if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen)
|
||||||
Emote = EMOTE_NORMAL;
|
Emote = EMOTE_NORMAL;
|
||||||
|
|
|
@ -922,7 +922,7 @@ void CGameContext::OnTick()
|
||||||
GetPlayerChar(m_VoteCreator)->Team() != GetPlayerChar(i)->Team())))
|
GetPlayerChar(m_VoteCreator)->Team() != GetPlayerChar(i)->Team())))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(m_apPlayers[i]->m_Afk && i != m_VoteCreator)
|
if(m_apPlayers[i]->IsAfk() && i != m_VoteCreator)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// can't vote in kick and spec votes in the beginning after joining
|
// can't vote in kick and spec votes in the beginning after joining
|
||||||
|
@ -973,7 +973,7 @@ void CGameContext::OnTick()
|
||||||
if(i != j && (!m_apPlayers[j] || str_comp(aaBuf[j], aaBuf[i]) != 0))
|
if(i != j && (!m_apPlayers[j] || str_comp(aaBuf[j], aaBuf[i]) != 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(m_apPlayers[j] && !m_apPlayers[j]->m_Afk && m_apPlayers[j]->GetTeam() != TEAM_SPECTATORS &&
|
if(m_apPlayers[j] && !m_apPlayers[j]->IsAfk() && m_apPlayers[j]->GetTeam() != TEAM_SPECTATORS &&
|
||||||
((Server()->Tick() - m_apPlayers[j]->m_JoinTick) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime ||
|
((Server()->Tick() - m_apPlayers[j]->m_JoinTick) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime ||
|
||||||
(m_apPlayers[j]->GetCharacter() && m_apPlayers[j]->GetCharacter()->m_DDRaceState == DDRACE_STARTED &&
|
(m_apPlayers[j]->GetCharacter() && m_apPlayers[j]->GetCharacter()->m_DDRaceState == DDRACE_STARTED &&
|
||||||
(Server()->Tick() - m_apPlayers[j]->GetCharacter()->m_StartTime) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime)))
|
(Server()->Tick() - m_apPlayers[j]->GetCharacter()->m_StartTime) / (Server()->TickSpeed() * 60) > g_Config.m_SvVoteVetoTime)))
|
||||||
|
@ -1488,6 +1488,7 @@ bool CGameContext::OnClientDataPersist(int ClientID, void *pData)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pPersistent->m_IsSpectator = m_apPlayers[ClientID]->GetTeam() == TEAM_SPECTATORS;
|
pPersistent->m_IsSpectator = m_apPlayers[ClientID]->GetTeam() == TEAM_SPECTATORS;
|
||||||
|
pPersistent->m_IsAfk = m_apPlayers[ClientID]->IsAfk();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1495,9 +1496,11 @@ void CGameContext::OnClientConnected(int ClientID, void *pData)
|
||||||
{
|
{
|
||||||
CPersistentClientData *pPersistentData = (CPersistentClientData *)pData;
|
CPersistentClientData *pPersistentData = (CPersistentClientData *)pData;
|
||||||
bool Spec = false;
|
bool Spec = false;
|
||||||
|
bool Afk = true;
|
||||||
if(pPersistentData)
|
if(pPersistentData)
|
||||||
{
|
{
|
||||||
Spec = pPersistentData->m_IsSpectator;
|
Spec = pPersistentData->m_IsSpectator;
|
||||||
|
Afk = pPersistentData->m_IsAfk;
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -1522,6 +1525,7 @@ void CGameContext::OnClientConnected(int ClientID, void *pData)
|
||||||
if(m_apPlayers[ClientID])
|
if(m_apPlayers[ClientID])
|
||||||
delete m_apPlayers[ClientID];
|
delete m_apPlayers[ClientID];
|
||||||
m_apPlayers[ClientID] = new(ClientID) CPlayer(this, NextUniqueClientID, ClientID, StartTeam);
|
m_apPlayers[ClientID] = new(ClientID) CPlayer(this, NextUniqueClientID, ClientID, StartTeam);
|
||||||
|
m_apPlayers[ClientID]->SetAfk(Afk);
|
||||||
NextUniqueClientID += 1;
|
NextUniqueClientID += 1;
|
||||||
|
|
||||||
#ifdef CONF_DEBUG
|
#ifdef CONF_DEBUG
|
||||||
|
@ -4361,6 +4365,6 @@ void CGameContext::OnUpdatePlayerServerInfo(char *aBuf, int BufSize, int ID)
|
||||||
"\"afk\":%s,"
|
"\"afk\":%s,"
|
||||||
"\"team\":%d",
|
"\"team\":%d",
|
||||||
aJsonSkin,
|
aJsonSkin,
|
||||||
JsonBool(m_apPlayers[ID]->m_Afk),
|
JsonBool(m_apPlayers[ID]->IsAfk()),
|
||||||
m_apPlayers[ID]->GetTeam());
|
m_apPlayers[ID]->GetTeam());
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,6 +127,7 @@ class CGameContext : public IGameServer
|
||||||
struct CPersistentClientData
|
struct CPersistentClientData
|
||||||
{
|
{
|
||||||
bool m_IsSpectator;
|
bool m_IsSpectator;
|
||||||
|
bool m_IsAfk;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -686,16 +686,24 @@ void CPlayer::UpdatePlaytime()
|
||||||
|
|
||||||
void CPlayer::AfkTimer()
|
void CPlayer::AfkTimer()
|
||||||
{
|
{
|
||||||
if(g_Config.m_SvMaxAfkTime == 0)
|
m_Afk = g_Config.m_SvMaxAfkTime != 0 && m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkTime;
|
||||||
return;
|
}
|
||||||
|
|
||||||
if(m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkTime)
|
void CPlayer::SetAfk(bool Afk)
|
||||||
|
{
|
||||||
|
if(g_Config.m_SvMaxAfkTime == 0)
|
||||||
{
|
{
|
||||||
m_Afk = true;
|
m_Afk = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Afk = false;
|
m_Afk = Afk;
|
||||||
|
|
||||||
|
// Ensure that the AFK state is not reset again automatically
|
||||||
|
if(Afk)
|
||||||
|
m_LastPlaytime = time_get() - time_freq() * g_Config.m_SvMaxAfkTime - 1;
|
||||||
|
else
|
||||||
|
m_LastPlaytime = time_get();
|
||||||
}
|
}
|
||||||
|
|
||||||
int CPlayer::GetDefaultEmote() const
|
int CPlayer::GetDefaultEmote() const
|
||||||
|
|
|
@ -140,6 +140,7 @@ private:
|
||||||
int m_Paused;
|
int m_Paused;
|
||||||
int64_t m_ForcePauseTime;
|
int64_t m_ForcePauseTime;
|
||||||
int64_t m_LastPause;
|
int64_t m_LastPause;
|
||||||
|
bool m_Afk;
|
||||||
|
|
||||||
int m_DefEmote;
|
int m_DefEmote;
|
||||||
int m_OverrideEmote;
|
int m_OverrideEmote;
|
||||||
|
@ -181,7 +182,6 @@ public:
|
||||||
vec2 m_ShowDistance;
|
vec2 m_ShowDistance;
|
||||||
bool m_SpecTeam;
|
bool m_SpecTeam;
|
||||||
bool m_NinjaJetpack;
|
bool m_NinjaJetpack;
|
||||||
bool m_Afk;
|
|
||||||
bool m_HasFinishScore;
|
bool m_HasFinishScore;
|
||||||
|
|
||||||
int m_ChatScore;
|
int m_ChatScore;
|
||||||
|
@ -190,6 +190,9 @@ public:
|
||||||
|
|
||||||
void UpdatePlaytime();
|
void UpdatePlaytime();
|
||||||
void AfkTimer();
|
void AfkTimer();
|
||||||
|
void SetAfk(bool Afk);
|
||||||
|
bool IsAfk() const { return m_Afk; }
|
||||||
|
|
||||||
int64_t m_LastPlaytime;
|
int64_t m_LastPlaytime;
|
||||||
int64_t m_LastEyeEmote;
|
int64_t m_LastEyeEmote;
|
||||||
int64_t m_LastBroadcast;
|
int64_t m_LastBroadcast;
|
||||||
|
|
Loading…
Reference in a new issue