mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Merge #5388
5388: Remove obsolete AfkTimer function r=def- a=ardadem
It does the same job with: 425f07c03d/src/game/server/gamecontroller.cpp (L48)
## 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 if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] 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: Arda Demir <ddmirarda@gmail.com>
This commit is contained in:
commit
ae1876d141
|
@ -331,8 +331,7 @@ MACRO_CONFIG_INT(ClBackgroundShowTilesLayers, cl_background_show_tiles_layers, 0
|
|||
MACRO_CONFIG_INT(SvShowOthers, sv_show_others, 1, 0, 1, CFGFLAG_SERVER, "Whether players can use the command showothers or not")
|
||||
MACRO_CONFIG_INT(SvShowOthersDefault, sv_show_others_default, 0, 0, 2, CFGFLAG_SERVER | CFGFLAG_GAME, "Whether players see others by default (2 for own team)")
|
||||
MACRO_CONFIG_INT(SvShowAllDefault, sv_show_all_default, 0, 0, 1, CFGFLAG_SERVER, "Whether players see all tees by default")
|
||||
MACRO_CONFIG_INT(SvMaxAfkTime, sv_max_afk_time, 0, 0, 9999, CFGFLAG_SERVER, "The time in seconds a player is allowed to be afk (0 = disabled)")
|
||||
MACRO_CONFIG_INT(SvMaxAfkVoteTime, sv_max_afk_vote_time, 300, 0, 9999, CFGFLAG_SERVER, "The time in seconds a player can be afk and his votes still count (0 = disabled)")
|
||||
MACRO_CONFIG_INT(SvMaxAfkTime, sv_max_afk_time, 300, 0, 9999, CFGFLAG_SERVER, "The time in seconds a player to be afk (0 = disabled)")
|
||||
MACRO_CONFIG_INT(SvPlasmaRange, sv_plasma_range, 700, 1, 99999, CFGFLAG_SERVER | CFGFLAG_GAME, "How far will the plasma gun track tees")
|
||||
MACRO_CONFIG_INT(SvPlasmaPerSec, sv_plasma_per_sec, 3, 0, 50, CFGFLAG_SERVER | CFGFLAG_GAME, "How many shots does the plasma gun fire per seconds")
|
||||
MACRO_CONFIG_INT(SvDraggerRange, sv_dragger_range, 700, 1, 99999, CFGFLAG_SERVER | CFGFLAG_GAME, "How far will the dragger track tees")
|
||||
|
|
|
@ -57,7 +57,6 @@ void CPlayer::Reset()
|
|||
|
||||
m_LastCommandPos = 0;
|
||||
m_LastPlaytime = 0;
|
||||
mem_zero(m_SentAfkWarning, sizeof(m_SentAfkWarning));
|
||||
m_ChatScore = 0;
|
||||
m_Moderating = false;
|
||||
m_EyeEmoteEnabled = true;
|
||||
|
@ -505,7 +504,7 @@ void CPlayer::OnPredictedInput(CNetObj_PlayerInput *NewInput)
|
|||
if((m_PlayerFlags & PLAYERFLAG_CHATTING) && (NewInput->m_PlayerFlags & PLAYERFLAG_CHATTING))
|
||||
return;
|
||||
|
||||
AfkVoteTimer(NewInput);
|
||||
AfkTimer();
|
||||
|
||||
m_NumInputs++;
|
||||
|
||||
|
@ -527,9 +526,7 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput)
|
|||
if(NewInput->m_PlayerFlags)
|
||||
Server()->SetClientFlags(m_ClientID, NewInput->m_PlayerFlags);
|
||||
|
||||
if(AfkTimer(NewInput))
|
||||
return; // we must return if kicked, as player struct is already deleted
|
||||
AfkVoteTimer(NewInput);
|
||||
AfkTimer();
|
||||
|
||||
if(((!m_pCharacter && m_Team == TEAM_SPECTATORS) || m_Paused) && m_SpectatorID == SPEC_FREEVIEW)
|
||||
m_ViewPos = vec2(NewInput->m_TargetX, NewInput->m_TargetY);
|
||||
|
@ -693,70 +690,17 @@ void CPlayer::TryRespawn()
|
|||
m_pCharacter->SetSolo(true);
|
||||
}
|
||||
|
||||
bool CPlayer::AfkTimer(CNetObj_PlayerInput *pNewTarget)
|
||||
{
|
||||
/*
|
||||
afk timer (x, y = mouse coordinates)
|
||||
Since a player has to move the mouse to play, this is a better method than checking
|
||||
the player's position in the game world, because it can easily be bypassed by just locking a key.
|
||||
Frozen players could be kicked as well, because they can't move.
|
||||
It also works for spectators.
|
||||
returns true if kicked
|
||||
*/
|
||||
|
||||
if(Server()->GetAuthedState(m_ClientID))
|
||||
return false; // don't kick admins
|
||||
if(g_Config.m_SvMaxAfkTime == 0)
|
||||
return false; // 0 = disabled
|
||||
|
||||
if(pNewTarget->m_TargetX != m_pLastTarget->m_TargetX || pNewTarget->m_TargetY != m_pLastTarget->m_TargetY)
|
||||
{
|
||||
UpdatePlaytime();
|
||||
// we shouldn't update m_pLastTarget here
|
||||
mem_zero(m_SentAfkWarning, sizeof(m_SentAfkWarning)); // resetting warnings
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!m_Paused)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
void CPlayer::UpdatePlaytime()
|
||||
{
|
||||
m_LastPlaytime = time_get();
|
||||
}
|
||||
|
||||
void CPlayer::AfkVoteTimer(CNetObj_PlayerInput *NewTarget)
|
||||
void CPlayer::AfkTimer()
|
||||
{
|
||||
if(g_Config.m_SvMaxAfkVoteTime == 0)
|
||||
if(g_Config.m_SvMaxAfkTime == 0)
|
||||
return;
|
||||
|
||||
if(m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkVoteTime)
|
||||
if(m_LastPlaytime < time_get() - time_freq() * g_Config.m_SvMaxAfkTime)
|
||||
{
|
||||
m_Afk = true;
|
||||
return;
|
||||
|
|
|
@ -179,9 +179,8 @@ public:
|
|||
|
||||
bool m_Moderating;
|
||||
|
||||
bool AfkTimer(CNetObj_PlayerInput *pNewTarget); // returns true if kicked
|
||||
void UpdatePlaytime();
|
||||
void AfkVoteTimer(CNetObj_PlayerInput *pNewTarget);
|
||||
void AfkTimer();
|
||||
int64_t m_LastPlaytime;
|
||||
int64_t m_LastEyeEmote;
|
||||
int64_t m_LastBroadcast;
|
||||
|
@ -189,12 +188,6 @@ public:
|
|||
|
||||
CNetObj_PlayerInput *m_pLastTarget;
|
||||
bool m_LastTargetInit;
|
||||
/*
|
||||
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