From 1e88ad92a09b9c247919be5a7973ce08276b7af1 Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Thu, 18 Jan 2018 07:56:07 +0100 Subject: [PATCH 1/5] add vote_no command and show auth rank in force vote --- src/game/ddracecommands.h | 1 + src/game/server/ddracecommands.cpp | 17 +++++++++++++++++ src/game/server/gamecontext.cpp | 3 ++- src/game/server/gamecontext.h | 1 + src/game/server/player.cpp | 14 ++++++++++++++ src/game/server/player.h | 2 ++ 6 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index 554fd1a8b..9dbee4244 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -48,6 +48,7 @@ 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("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\", used by helpers") 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 0feb6fa97..8bc2a19dc 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -573,3 +573,20 @@ void CGameContext::ConUnFreezeHammer(IConsole::IResult *pResult, void *pUserData pChr->m_FreezeHammer = false; } +void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + + // check if there is a vote running + if(!pSelf->m_VoteCloseTime) + return; + + pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_NO_ADMIN; + pSelf->m_VoteEnforcer = pResult->m_ClientID; + char aBuf[256]; + str_format(aBuf, sizeof(aBuf), "%s forced vote %s", pResult->GetString(0), + pSelf->m_apPlayers[pResult->m_ClientID]->GetAuthStateName(true)); + pSelf->SendChatTarget(-1, aBuf); + str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); +} \ No newline at end of file diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 5f1aa3415..191bc79e1 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2421,7 +2421,8 @@ void CGameContext::ConVote(IConsole::IResult *pResult, void *pUserData) pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_NO_ADMIN; pSelf->m_VoteEnforcer = pResult->m_ClientID; char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "moderator forced vote %s", pResult->GetString(0)); + str_format(aBuf, sizeof(aBuf), "%s forced vote %s", pResult->GetString(0), + pSelf->m_apPlayers[pResult->m_ClientID]->GetAuthStateName(true)); pSelf->SendChatTarget(-1, aBuf); str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index c88c17512..5bb469841 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -336,6 +336,7 @@ private: static void ConSetTimerType(IConsole::IResult *pResult, void *pUserData); static void ConRescue(IConsole::IResult *pResult, void *pUserData); static void ConProtectedKill(IConsole::IResult *pResult, void *pUserData); + static void ConVoteNo(IConsole::IResult *pResult, void *pUserData); static void ConMute(IConsole::IResult *pResult, void *pUserData); static void ConMuteID(IConsole::IResult *pResult, void *pUserData); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index aba398ed0..09b05b8cf 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -778,3 +778,17 @@ void CPlayer::SpectatePlayerName(const char *pName) } } } + +const char* CPlayer::GetAuthStateName(bool IsFirstWord) +{ + int State = Server()->GetAuthedState(m_ClientID); + + if(State == IServer::AUTHED_HELPER) + return IsFirstWord ? "Helper" : "helper"; + if(State == IServer::AUTHED_MOD) + return IsFirstWord ? "Moderator" : "moderator"; + if(State == IServer::AUTHED_NO) + return IsFirstWord ? "Admin" : "admin"; + + return IsFirstWord ? "User" : "user"; +} diff --git a/src/game/server/player.h b/src/game/server/player.h index 60ce2fce6..7141640bd 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -160,6 +160,8 @@ public: int Pause(int State, bool Force); int ForcePause(int Time); int IsPaused(); + + const char* GetAuthStateName(bool IsFirstWord = false); bool IsPlaying(); int64 m_Last_KickVote; From 6413cab70206355b00e5f5f4bcf1baf64e3b9845 Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Thu, 18 Jan 2018 07:58:22 +0100 Subject: [PATCH 2/5] forgot newline --- src/game/server/ddracecommands.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/ddracecommands.cpp b/src/game/server/ddracecommands.cpp index 8bc2a19dc..eb3386734 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -589,4 +589,4 @@ void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData) pSelf->SendChatTarget(-1, aBuf); str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); -} \ No newline at end of file +} From e59387a304ee32e6a5affdde8aeccbe2d418d345 Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Thu, 18 Jan 2018 16:17:23 +0100 Subject: [PATCH 3/5] revision changes --- src/game/ddracecommands.h | 2 +- src/game/server/ddracecommands.cpp | 13 +----------- src/game/server/gamecontext.cpp | 32 ++++++++++++++++++------------ src/game/server/gamecontext.h | 3 ++- src/game/server/player.cpp | 14 ------------- src/game/server/player.h | 2 -- 6 files changed, 23 insertions(+), 43 deletions(-) diff --git a/src/game/ddracecommands.h b/src/game/ddracecommands.h index 9dbee4244..31c69ba77 100644 --- a/src/game/ddracecommands.h +++ b/src/game/ddracecommands.h @@ -48,7 +48,7 @@ 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("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\", used by helpers") +CONSOLE_COMMAND("vote_no", "", CFGFLAG_SERVER, ConVoteNo, this, "Same as \"vote no\"") 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 eb3386734..a97e37783 100644 --- a/src/game/server/ddracecommands.cpp +++ b/src/game/server/ddracecommands.cpp @@ -577,16 +577,5 @@ void CGameContext::ConVoteNo(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - // check if there is a vote running - if(!pSelf->m_VoteCloseTime) - return; - - pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_NO_ADMIN; - pSelf->m_VoteEnforcer = pResult->m_ClientID; - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%s forced vote %s", pResult->GetString(0), - pSelf->m_apPlayers[pResult->m_ClientID]->GetAuthStateName(true)); - pSelf->SendChatTarget(-1, aBuf); - str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + pSelf->ForceVote(pResult->m_ClientID, false); } diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 191bc79e1..ddf67b53e 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -2411,21 +2411,10 @@ void CGameContext::ConVote(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - // check if there is a vote running - if(!pSelf->m_VoteCloseTime) - return; - if(str_comp_nocase(pResult->GetString(0), "yes") == 0) - pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_YES_ADMIN; + pSelf->ForceVote(pResult->m_ClientID, true); else if(str_comp_nocase(pResult->GetString(0), "no") == 0) - pSelf->m_VoteEnforce = CGameContext::VOTE_ENFORCE_NO_ADMIN; - pSelf->m_VoteEnforcer = pResult->m_ClientID; - char aBuf[256]; - str_format(aBuf, sizeof(aBuf), "%s forced vote %s", pResult->GetString(0), - pSelf->m_apPlayers[pResult->m_ClientID]->GetAuthStateName(true)); - pSelf->SendChatTarget(-1, aBuf); - str_format(aBuf, sizeof(aBuf), "forcing vote %s", pResult->GetString(0)); - pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + pSelf->ForceVote(pResult->m_ClientID, false); } void CGameContext::ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) @@ -3395,3 +3384,20 @@ bool CGameContext::PlayerModerating() } return false; } + +void CGameContext::ForceVote(int EnforcerID, bool Success) +{ + // check if there is a vote running + if(m_VoteCloseTime) + return; + + m_VoteEnforce = Success ? CGameContext::VOTE_ENFORCE_YES_ADMIN : CGameContext::VOTE_ENFORCE_NO_ADMIN; + m_VoteEnforcer = EnforcerID; + + char aBuf[256]; + const char* Option = Success ? "yes" : "no"; + str_format(aBuf, sizeof(aBuf), "moderator forced vote %s", Option); + SendChatTarget(-1, aBuf); + str_format(aBuf, sizeof(aBuf), "forcing vote %s", Option); + Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); +} diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 5bb469841..41dd22b8a 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -101,6 +101,7 @@ class CGameContext : public IGameServer static void ConForceVote(IConsole::IResult *pResult, void *pUserData); static void ConClearVotes(IConsole::IResult *pResult, void *pUserData); static void ConVote(IConsole::IResult *pResult, void *pUserData); + static void ConVoteNo(IConsole::IResult *pResult, void *pUserData); static void ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); CGameContext(int Resetting); @@ -247,6 +248,7 @@ public: bool PlayerExists(int ClientID) { return m_apPlayers[ClientID]; }; // Returns true if someone is actively moderating. bool PlayerModerating(); + void ForceVote(int EnforcerID, bool Success); private: @@ -336,7 +338,6 @@ private: static void ConSetTimerType(IConsole::IResult *pResult, void *pUserData); static void ConRescue(IConsole::IResult *pResult, void *pUserData); static void ConProtectedKill(IConsole::IResult *pResult, void *pUserData); - static void ConVoteNo(IConsole::IResult *pResult, void *pUserData); static void ConMute(IConsole::IResult *pResult, void *pUserData); static void ConMuteID(IConsole::IResult *pResult, void *pUserData); diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 09b05b8cf..aba398ed0 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -778,17 +778,3 @@ void CPlayer::SpectatePlayerName(const char *pName) } } } - -const char* CPlayer::GetAuthStateName(bool IsFirstWord) -{ - int State = Server()->GetAuthedState(m_ClientID); - - if(State == IServer::AUTHED_HELPER) - return IsFirstWord ? "Helper" : "helper"; - if(State == IServer::AUTHED_MOD) - return IsFirstWord ? "Moderator" : "moderator"; - if(State == IServer::AUTHED_NO) - return IsFirstWord ? "Admin" : "admin"; - - return IsFirstWord ? "User" : "user"; -} diff --git a/src/game/server/player.h b/src/game/server/player.h index 7141640bd..60ce2fce6 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -160,8 +160,6 @@ public: int Pause(int State, bool Force); int ForcePause(int Time); int IsPaused(); - - const char* GetAuthStateName(bool IsFirstWord = false); bool IsPlaying(); int64 m_Last_KickVote; From e039145628057e2b988bd10706932f6f695ce9f2 Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Thu, 18 Jan 2018 18:30:38 +0100 Subject: [PATCH 4/5] fix pointer naming --- src/game/server/gamecontext.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index ddf67b53e..7770b880d 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -3395,9 +3395,9 @@ void CGameContext::ForceVote(int EnforcerID, bool Success) m_VoteEnforcer = EnforcerID; char aBuf[256]; - const char* Option = Success ? "yes" : "no"; - str_format(aBuf, sizeof(aBuf), "moderator forced vote %s", Option); + const char* pOption = Success ? "yes" : "no"; + str_format(aBuf, sizeof(aBuf), "moderator forced vote %s", pOption); SendChatTarget(-1, aBuf); - str_format(aBuf, sizeof(aBuf), "forcing vote %s", Option); + str_format(aBuf, sizeof(aBuf), "forcing vote %s", pOption); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); } From 0f328d6c521e773935b8dbb1f129b2ef153196d2 Mon Sep 17 00:00:00 2001 From: Ryozuki Date: Thu, 18 Jan 2018 18:41:37 +0100 Subject: [PATCH 5/5] wrong side.. --- src/game/server/gamecontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 7770b880d..654a9230f 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -3395,7 +3395,7 @@ void CGameContext::ForceVote(int EnforcerID, bool Success) m_VoteEnforcer = EnforcerID; char aBuf[256]; - const char* pOption = Success ? "yes" : "no"; + const char *pOption = Success ? "yes" : "no"; str_format(aBuf, sizeof(aBuf), "moderator forced vote %s", pOption); SendChatTarget(-1, aBuf); str_format(aBuf, sizeof(aBuf), "forcing vote %s", pOption);