From 14f98a9dedf21b9d73227651f3499fff66432a8f Mon Sep 17 00:00:00 2001 From: Johannes Loher Date: Mon, 23 May 2011 13:06:38 +0200 Subject: [PATCH] Added possibility to deny changing of team after a set_team for a certain amount of time. Added server setting to do this automatically for spec votes. fixes #640. --- src/game/client/gameclient.cpp | 2 +- src/game/server/gamecontext.cpp | 20 +++++++++++++++++--- src/game/server/player.cpp | 1 + src/game/server/player.h | 1 + src/game/variables.h | 1 + 5 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 0fffb77c5..41f7e8fa6 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -196,7 +196,7 @@ void CGameClient::OnConsoleInit() Console()->Register("restart", "?i", CFGFLAG_SERVER, 0, 0, "Restart in x seconds"); Console()->Register("broadcast", "r", CFGFLAG_SERVER, 0, 0, "Broadcast message"); Console()->Register("say", "r", CFGFLAG_SERVER, 0, 0, "Say in chat"); - Console()->Register("set_team", "ii", CFGFLAG_SERVER, 0, 0, "Set team of player to team"); + Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, 0, 0, "Set team of player to team"); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, 0, 0, "Set team of all players to team"); Console()->Register("add_vote", "sr", CFGFLAG_SERVER, 0, 0, "Add a voting option"); Console()->Register("remove_vote", "s", CFGFLAG_SERVER, 0, 0, "remove a voting option"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 5fe25f2c9..9cec47e8e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -738,7 +738,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason); str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID)); - str_format(aCmd, sizeof(aCmd), "set_team %d -1", SpectateID); + str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay*60); } if(aCmd[0]) @@ -774,6 +774,15 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) if(pPlayer->GetTeam() == pMsg->m_Team || (g_Config.m_SvSpamprotection && pPlayer->m_LastSetTeam && pPlayer->m_LastSetTeam+Server()->TickSpeed()*3 > Server()->Tick())) return; + if(pPlayer->m_TeamChangeTick > Server()->Tick()) + { + int TimeLeft = (pPlayer->m_TeamChangeTick - Server()->Tick())/Server()->TickSpeed(); + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "Time to wait before changing team: %02d:%02d", TimeLeft/60, TimeLeft%60); + SendBroadcast(aBuf, ClientID); + return; + } + // Switch team on given client and kill/respawn him if(m_pController->CanJoinTeam(pMsg->m_Team, ClientID)) { @@ -784,6 +793,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) m_VoteUpdate = true; pPlayer->SetTeam(pMsg->m_Team); (void)m_pController->CheckTeamBalance(); + pPlayer->m_TeamChangeTick = Server()->Tick(); } else SendBroadcast("Teams must be balanced, please join other team", ClientID); @@ -1025,6 +1035,9 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) CGameContext *pSelf = (CGameContext *)pUserData; int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); + int Delay = 0; + if(pResult->NumArguments() > 2) + Delay = clamp(pResult->GetInteger(2), 0, 1000); char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team); @@ -1033,6 +1046,7 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) if(!pSelf->m_apPlayers[ClientID]) return; + pSelf->m_apPlayers[ClientID]->m_TeamChangeTick = pSelf->Server()->Tick()+pSelf->Server()->TickSpeed()*Delay; pSelf->m_apPlayers[ClientID]->SetTeam(Team); (void)pSelf->m_pController->CheckTeamBalance(); } @@ -1249,7 +1263,7 @@ void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) return; } - str_format(aBuf, sizeof(aBuf), "set_team %d -1", SpectateID); + str_format(aBuf, sizeof(aBuf), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay*60); pSelf->Console()->ExecuteLine(aBuf); } } @@ -1306,7 +1320,7 @@ void CGameContext::OnConsoleInit() Console()->Register("restart", "?i", CFGFLAG_SERVER|CFGFLAG_STORE, ConRestart, this, ""); Console()->Register("broadcast", "r", CFGFLAG_SERVER, ConBroadcast, this, ""); Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, ""); - Console()->Register("set_team", "ii", CFGFLAG_SERVER, ConSetTeam, this, ""); + Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, ""); Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, ""); Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, ""); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 2d092804c..1f822524e 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -20,6 +20,7 @@ CPlayer::CPlayer(CGameContext *pGameServer, int ClientID, int Team) m_Team = GameServer()->m_pController->ClampTeam(Team); m_SpectatorID = SPEC_FREEVIEW; m_LastActionTick = Server()->Tick(); + m_TeamChangeTick = Server()->Tick(); } CPlayer::~CPlayer() diff --git a/src/game/server/player.h b/src/game/server/player.h index de06bd3a1..b8c4ce6cd 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -78,6 +78,7 @@ public: int m_ScoreStartTick; bool m_ForceBalanced; int m_LastActionTick; + int m_TeamChangeTick; struct { int m_TargetX; diff --git a/src/game/variables.h b/src/game/variables.h index 1d681e1fe..3af299cf9 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -75,6 +75,7 @@ MACRO_CONFIG_INT(SvInactiveKick, sv_inactivekick, 1, 0, 2, CFGFLAG_SERVER, "How MACRO_CONFIG_INT(SvStrictSpectateMode, sv_strict_spectate_mode, 0, 0, 1, CFGFLAG_SERVER, "Restricts information in spectator mode") MACRO_CONFIG_INT(SvVoteSpectate, sv_vote_spectate, 1, 0, 1, CFGFLAG_SERVER, "Allow voting to move players to spectators") +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(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")