Merge pull request #410 from heinrich5991/pr_ddnet_join_vote_delay

Add sv_join_vote_delay
This commit is contained in:
H-M-H 2016-01-29 12:58:05 +01:00
commit cb1c63c652
5 changed files with 53 additions and 8 deletions

View file

@ -934,6 +934,22 @@ void CGameContext::OnClientEnter(int ClientID)
void CGameContext::OnClientConnected(int ClientID) void CGameContext::OnClientConnected(int ClientID)
{ {
{
bool Empty = true;
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(m_apPlayers[i])
{
Empty = false;
break;
}
}
if(Empty)
{
m_NonEmptySince = Server()->Tick();
}
}
// Check which team the player should be on // Check which team the player should be on
const int StartTeam = g_Config.m_SvTournamentMode ? TEAM_SPECTATORS : m_pController->GetAutoTeam(ClientID); const int StartTeam = g_Config.m_SvTournamentMode ? TEAM_SPECTATORS : m_pController->GetAutoTeam(ClientID);
@ -1119,12 +1135,13 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
} }
else if(MsgID == NETMSGTYPE_CL_CALLVOTE) else if(MsgID == NETMSGTYPE_CL_CALLVOTE)
{ {
if(g_Config.m_SvSpamprotection && pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry+Server()->TickSpeed()*3 > Server()->Tick()) int64 Now = Server()->Tick();
int64 TickSpeed = Server()->TickSpeed();
if(g_Config.m_SvSpamprotection && pPlayer->m_LastVoteTry && pPlayer->m_LastVoteTry + TickSpeed * 3 > Now)
return; return;
int64 Now = Server()->Tick();
pPlayer->m_LastVoteTry = Now; pPlayer->m_LastVoteTry = Now;
//if(pPlayer->GetTeam() == TEAM_SPECTATORS)
if(g_Config.m_SvSpectatorVotes == 0 && pPlayer->GetTeam() == TEAM_SPECTATORS) if(g_Config.m_SvSpectatorVotes == 0 && pPlayer->GetTeam() == TEAM_SPECTATORS)
{ {
SendChatTarget(ClientID, "Spectators aren't allowed to start a vote."); SendChatTarget(ClientID, "Spectators aren't allowed to start a vote.");
@ -1137,11 +1154,19 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
return; return;
} }
int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*g_Config.m_SvVoteDelay - Now; if(g_Config.m_SvJoinVoteDelay && Now < pPlayer->m_FirstVoteTick)
if(pPlayer->m_LastVoteCall && Timeleft > 0)
{ {
char aChatmsg[512] = {0}; char aBuf[64];
str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d seconds before making another vote", (Timeleft/Server()->TickSpeed())+1); str_format(aBuf, sizeof(aBuf), "You must wait %d seconds before making your first vote", ((pPlayer->m_FirstVoteTick - Now) / TickSpeed) + 1);
SendChatTarget(ClientID, aBuf);
return;
}
int TimeLeft = pPlayer->m_LastVoteCall + TickSpeed * g_Config.m_SvVoteDelay - Now;
if(pPlayer->m_LastVoteCall && TimeLeft > 0)
{
char aChatmsg[64];
str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d seconds before making another vote", (TimeLeft/TickSpeed)+1);
SendChatTarget(ClientID, aChatmsg); SendChatTarget(ClientID, aChatmsg);
return; return;
} }

View file

@ -223,6 +223,8 @@ public:
int ProcessSpamProtection(int ClientID); int ProcessSpamProtection(int ClientID);
int GetDDRaceTeam(int ClientID); int GetDDRaceTeam(int ClientID);
// Describes the time when the first player joined the server.
int64 m_NonEmptySince;
int64 m_LastMapVote; int64 m_LastMapVote;
private: private:

View file

@ -125,6 +125,22 @@ void CPlayer::Reset()
#if defined(CONF_SQL) #if defined(CONF_SQL)
m_LastSQLQuery = 0; m_LastSQLQuery = 0;
#endif #endif
int64 Now = Server()->Tick();
int64 TickSpeed = Server()->TickSpeed();
// If the player joins within ten seconds of the server becoming
// non-empty, allow them to vote immediately. This allows players to
// vote after map changes or when they join an empty server.
//
// Otherwise, block voting for 60 seconds after joining.
if(Now > GameServer()->m_NonEmptySince + 10 * TickSpeed)
{
m_FirstVoteTick = Now + 60 * TickSpeed;
}
else
{
m_FirstVoteTick = Now;
}
} }
void CPlayer::Tick() void CPlayer::Tick()

View file

@ -138,6 +138,7 @@ public:
int m_Paused; int m_Paused;
bool m_DND; bool m_DND;
int64 m_FirstVoteTick;
int64 m_NextPauseTick; int64 m_NextPauseTick;
char m_TimeoutCode[64]; char m_TimeoutCode[64];

View file

@ -148,7 +148,8 @@ MACRO_CONFIG_INT(SvVoteSpectate, sv_vote_spectate, 1, 0, 1, CFGFLAG_SERVER, "All
MACRO_CONFIG_INT(SvVoteSpectateRejoindelay, sv_vote_spectate_rejoindelay, 3, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before a player can rejoin after being moved to spectators by vote") MACRO_CONFIG_INT(SvVoteSpectateRejoindelay, sv_vote_spectate_rejoindelay, 3, 0, 1000, CFGFLAG_SERVER, "How many minutes to wait before a player can rejoin after being moved to spectators by vote")
MACRO_CONFIG_INT(SvVoteKick, sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players") MACRO_CONFIG_INT(SvVoteKick, sv_vote_kick, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to kick players")
MACRO_CONFIG_INT(SvVoteKickMin, sv_vote_kick_min, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Minimum number of players required to start a kick vote") MACRO_CONFIG_INT(SvVoteKickMin, sv_vote_kick_min, 0, 0, MAX_CLIENTS, CFGFLAG_SERVER, "Minimum number of players required to start a kick vote")
MACRO_CONFIG_INT(SvVoteKickBantime, sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time to ban a player if kicked by vote. 0 makes it just use kick") MACRO_CONFIG_INT(SvVoteKickBantime, sv_vote_kick_bantime, 5, 0, 1440, CFGFLAG_SERVER, "The time in seconds to ban a player if kicked by vote. 0 makes it just use kick")
MACRO_CONFIG_INT(SvJoinVoteDelay, sv_join_vote_delay, 1, 0, 1, CFGFLAG_SERVER, "Add a delay before recently joined players can vote")
MACRO_CONFIG_INT(SvOldTeleportWeapons, sv_old_teleport_weapons, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Teleporting of all weapons (deprecated, use special entities instead)"); MACRO_CONFIG_INT(SvOldTeleportWeapons, sv_old_teleport_weapons, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Teleporting of all weapons (deprecated, use special entities instead)");
MACRO_CONFIG_INT(SvOldTeleportHook, sv_old_teleport_hook, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Hook through teleporter (deprecated, use special entities instead)"); MACRO_CONFIG_INT(SvOldTeleportHook, sv_old_teleport_hook, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Hook through teleporter (deprecated, use special entities instead)");
MACRO_CONFIG_INT(SvTeleportHoldHook, sv_teleport_hold_hook, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Hold hook when teleported"); MACRO_CONFIG_INT(SvTeleportHoldHook, sv_teleport_hold_hook, 0, 0, 1, CFGFLAG_SERVER|CFGFLAG_GAME, "Hold hook when teleported");