From d6eb604718ab7671a5780e368f6b5cbc92f4891d Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Fri, 5 Jan 2018 12:04:06 +0100 Subject: [PATCH] add rcon moderate mode --- autoexec_server.cfg | 1 + src/game/ddracecommands.h | 1 + src/game/server/ddracecommands.cpp | 28 ++++++++++++++ src/game/server/gamecontext.cpp | 62 ++++++++++++++++++++++++++---- src/game/server/gamecontext.h | 5 ++- src/game/server/player.cpp | 18 +++++++++ src/game/server/player.h | 2 + 7 files changed, 108 insertions(+), 9 deletions(-) diff --git a/autoexec_server.cfg b/autoexec_server.cfg index bd4288e03..fac34990c 100644 --- a/autoexec_server.cfg +++ b/autoexec_server.cfg @@ -181,6 +181,7 @@ access_level bans 1 access_level bans_save 1 access_level kick 1 access_level force_vote 1 +access_level moderate 1 diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index 7388119ca..46057d1d0 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -47,6 +47,7 @@ CONSOLE_COMMAND("muteid", "v[id] i[seconds]", CFGFLAG_SERVER, ConMuteID, this, " CONSOLE_COMMAND("muteip", "s[ip] i[seconds]", CFGFLAG_SERVER, ConMuteIP, this, ""); CONSOLE_COMMAND("unmute", "v[id]", CFGFLAG_SERVER, ConUnmute, this, ""); CONSOLE_COMMAND("mutes", "", CFGFLAG_SERVER, ConMutes, this, ""); +CONSOLE_COMMAND("moderate", "", CFGFLAG_SERVER, ConModerate, this, "Enables/disables active moderator mode for the player") CONSOLE_COMMAND("freezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConFreezeHammer, this, "Gives a player Freeze Hammer") CONSOLE_COMMAND("unfreezehammer", "v[id]", CFGFLAG_SERVER|CMDFLAG_TEST, ConUnFreezeHammer, this, "Removes Freeze Hammer from a player") diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index f5e14f4f3..c9bac81fe 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -461,6 +461,34 @@ void CGameContext::ConMutes(IConsole::IResult *pResult, void *pUserData) } } +void CGameContext::ConModerate(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + if (!CheckClientID(pResult->m_ClientID)) + return; + + bool HadModerator = pSelf->PlayerModerating(); + + CPlayer* player = pSelf->m_apPlayers[pResult->m_ClientID]; + player->m_Moderating = !player->m_Moderating; + + char aBuf[256]; + + if(!HadModerator && player->m_Moderating) + str_format(aBuf, sizeof(aBuf), "Server kick/spec votes will now be actively moderated."); + + if (!pSelf->PlayerModerating()) + str_format(aBuf, sizeof(aBuf), "Server kick/spec votes are no longer actively moderated."); + + pSelf->SendChat(-1, CHAT_ALL, aBuf, 0); + + if(player->m_Moderating) + pSelf->SendChatTarget(pResult->m_ClientID, + "Active moderator mode enabled for you."); + else + pSelf->SendChatTarget(pResult->m_ClientID, "Active moderator mode disabled for you."); +} + void CGameContext::ConList(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index f672a1908..8697e35b7 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -740,6 +740,26 @@ void CGameContext::OnTick() else if(ActVote < 0) VetoStop = true; } + + // Check if a active moderator has voted. + if (m_apPlayers[i] && m_apPlayers[i]->m_Vote != 0 && m_apPlayers[i]->m_Moderating) + { + if (m_apPlayers[i]->m_Vote == 1) + { + Server()->SetRconCID(IServer::RCON_CID_VOTE); + Console()->ExecuteLine(m_aVoteCommand); + Server()->SetRconCID(IServer::RCON_CID_SERV); + EndVote(); + SendChat(-1, CGameContext::CHAT_ALL, "Vote passed enforced by server moderator"); + return; + } + else if (m_apPlayers[i]->m_Vote == -1) + { + EndVote(); + SendChat(-1, CGameContext::CHAT_ALL, "Vote failed enforced by server moderator"); + return; + } + } } if(g_Config.m_SvVoteMaxTotal && Total > g_Config.m_SvVoteMaxTotal && @@ -762,14 +782,32 @@ void CGameContext::OnTick() if(m_VoteEnforce == VOTE_ENFORCE_YES) { - Server()->SetRconCID(IServer::RCON_CID_VOTE); - Console()->ExecuteLine(m_aVoteCommand); - Server()->SetRconCID(IServer::RCON_CID_SERV); - EndVote(); - SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); + if (PlayerModerating() && (m_VoteKick || m_VoteSpec)) + { + // Ensure minimum time for vote to end when moderating. + if (time_get() > m_VoteCloseTime) + { + Server()->SetRconCID(IServer::RCON_CID_VOTE); + Console()->ExecuteLine(m_aVoteCommand); + Server()->SetRconCID(IServer::RCON_CID_SERV); + EndVote(); + SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); - if(m_apPlayers[m_VoteCreator] && !m_VoteKick && !m_VoteSpec) - m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; + if (m_apPlayers[m_VoteCreator] && !m_VoteKick && !m_VoteSpec) + m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; + } + } + else + { + Server()->SetRconCID(IServer::RCON_CID_VOTE); + Console()->ExecuteLine(m_aVoteCommand); + Server()->SetRconCID(IServer::RCON_CID_SERV); + EndVote(); + SendChat(-1, CGameContext::CHAT_ALL, "Vote passed"); + + if (m_apPlayers[m_VoteCreator] && !m_VoteKick && !m_VoteSpec) + m_apPlayers[m_VoteCreator]->m_LastVoteCall = 0; + } } else if(m_VoteEnforce == VOTE_ENFORCE_YES_ADMIN) { @@ -3345,3 +3383,13 @@ void CGameContext::SetClientVersion(int ClientID, int Version) { } m_apPlayers[ClientID]->m_ClientVersion = Version; } + +bool CGameContext::PlayerModerating() +{ + for (int i = 0; i < MAX_CLIENTS; i++) + { + if (m_apPlayers[i] && m_apPlayers[i]->m_Moderating) + return true; + } + return false; +} diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index aa1ab3785..c88c17512 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -245,6 +245,8 @@ public: int GetClientVersion(int ClientID); void SetClientVersion(int ClientID, int Version); bool PlayerExists(int ClientID) { return m_apPlayers[ClientID]; }; + // Returns true if someone is actively moderating. + bool PlayerModerating(); private: @@ -335,13 +337,12 @@ private: static void ConRescue(IConsole::IResult *pResult, void *pUserData); static void ConProtectedKill(IConsole::IResult *pResult, void *pUserData); - - static void ConMute(IConsole::IResult *pResult, void *pUserData); static void ConMuteID(IConsole::IResult *pResult, void *pUserData); static void ConMuteIP(IConsole::IResult *pResult, void *pUserData); static void ConUnmute(IConsole::IResult *pResult, void *pUserData); static void ConMutes(IConsole::IResult *pResult, void *pUserData); + static void ConModerate(IConsole::IResult *pResult, void *pUserData); static void ConList(IConsole::IResult *pResult, void *pUserData); static void ConSetDDRTeam(IConsole::IResult *pResult, void *pUserData); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 2f7786187..aba398ed0 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -62,6 +62,7 @@ void CPlayer::Reset() m_Sent1stAfkWarning = 0; m_Sent2ndAfkWarning = 0; m_ChatScore = 0; + m_Moderating = false; m_EyeEmote = true; m_TimerType = (g_Config.m_SvDefaultTimerType == CPlayer::TIMERTYPE_GAMETIMER || g_Config.m_SvDefaultTimerType == CPlayer::TIMERTYPE_GAMETIMER_AND_BROADCAST) ? CPlayer::TIMERTYPE_BROADCAST : g_Config.m_SvDefaultTimerType; m_DefEmote = EMOTE_NORMAL; @@ -153,6 +154,15 @@ void CPlayer::Tick() Server()->SetClientScore(m_ClientID, m_Score); + if (m_Moderating && m_Afk) + { + m_Moderating = false; + GameServer()->SendChatTarget(m_ClientID, "Active moderator mode disabled because you are afk."); + + if (!GameServer()->PlayerModerating()) + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated."); + } + // do latency stuff { IServer::CClientInfo Info; @@ -374,6 +384,14 @@ void CPlayer::OnDisconnect(const char *pReason) str_format(aBuf, sizeof(aBuf), "leave player='%d:%s'", m_ClientID, Server()->ClientName(m_ClientID)); GameServer()->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "game", aBuf); + + bool WasModerator = m_Moderating; + + // Set this to false, otherwise PlayerModerating() will return true. + m_Moderating = false; + + if (!GameServer()->PlayerModerating() && WasModerator) + GameServer()->SendChat(-1, CGameContext::CHAT_ALL, "Server kick/spec votes are no longer actively moderated."); } CGameControllerDDRace* Controller = (CGameControllerDDRace*)GameServer()->m_pController; diff --git a/src/game/server/player.h b/src/game/server/player.h index 637faff92..60ce2fce6 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -176,6 +176,8 @@ public: int m_ChatScore; + bool m_Moderating; + bool AfkTimer(int new_target_x, int new_target_y); //returns true if kicked void AfkVoteTimer(CNetObj_PlayerInput *NewTarget); int64 m_LastPlaytime;