diff options
| author | oy <Tom_Adams@web.de> | 2011-03-25 12:06:45 +0100 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2011-03-25 12:06:45 +0100 |
| commit | 6ece07ee74b8b179d0a66c781a57344bcd75d3d5 (patch) | |
| tree | a6b6f2512a871814cb6b96013311371e84e47cef /src | |
| parent | 359b806e959fbdced610c2d84d1e12dfe7b58a7e (diff) | |
| download | zcatch-6ece07ee74b8b179d0a66c781a57344bcd75d3d5.tar.gz zcatch-6ece07ee74b8b179d0a66c781a57344bcd75d3d5.zip | |
added force_vote command
Diffstat (limited to 'src')
| -rw-r--r-- | src/game/client/components/menus_ingame.cpp | 8 | ||||
| -rw-r--r-- | src/game/client/components/voting.cpp | 49 | ||||
| -rw-r--r-- | src/game/client/components/voting.h | 6 | ||||
| -rw-r--r-- | src/game/client/gameclient.cpp | 1 | ||||
| -rw-r--r-- | src/game/server/gamecontext.cpp | 68 | ||||
| -rw-r--r-- | src/game/server/gamecontext.h | 1 |
6 files changed, 89 insertions, 44 deletions
diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index ad43fc20..06da001a 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -442,10 +442,10 @@ void CMenus::RenderServerControl(CUIRect MainView) m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { m_pClient->m_pVoting->CallvoteKick(m_CallvoteSelectedPlayer, m_aCallvoteReason); - m_aCallvoteReason[0] = 0; SetActive(false); } } + m_aCallvoteReason[0] = 0; } // render kick reason @@ -469,17 +469,17 @@ void CMenus::RenderServerControl(CUIRect MainView) if(DoButton_Menu(&s_ForceVoteButton, Localize("Force vote"), 0, &Button)) { if(s_ControlPage == 0) - m_pClient->m_pVoting->ForcevoteOption(m_CallvoteSelectedOption, m_aCallvoteReason); + m_pClient->m_pVoting->CallvoteOption(m_CallvoteSelectedOption, m_aCallvoteReason, true); else if(s_ControlPage == 1) { if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS && m_pClient->m_Snap.m_paPlayerInfos[m_CallvoteSelectedPlayer]) { - m_pClient->m_pVoting->ForcevoteKick(m_CallvoteSelectedPlayer, m_aCallvoteReason); - m_aCallvoteReason[0] = 0; + m_pClient->m_pVoting->CallvoteKick(m_CallvoteSelectedPlayer, m_aCallvoteReason, true); SetActive(false); } } + m_aCallvoteReason[0] = 0; } } } diff --git a/src/game/client/components/voting.cpp b/src/game/client/components/voting.cpp index 808b6669..6e00a5d5 100644 --- a/src/game/client/components/voting.cpp +++ b/src/game/client/components/voting.cpp @@ -31,48 +31,37 @@ void CVoting::Callvote(const char *pType, const char *pValue, const char *pReaso Client()->SendPackMsg(&Msg, MSGFLAG_VITAL); } -void CVoting::CallvoteKick(int ClientID, const char *pReason) +void CVoting::CallvoteKick(int ClientID, const char *pReason, bool ForceVote) { - char aBuf[32]; - str_format(aBuf, sizeof(aBuf), "%d", ClientID); - Callvote("kick", aBuf, pReason); -} - -void CVoting::CallvoteOption(int OptionId, const char *pReason) -{ - CVoteOption *pOption = m_pFirst; - while(pOption && OptionId >= 0) + if(ForceVote) { - if(OptionId == 0) - { - Callvote("option", pOption->m_aDescription, pReason); - break; - } - - OptionId--; - pOption = pOption->m_pNext; + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "force_vote kick %d %s", ClientID, pReason); + Client()->Rcon(aBuf); } -} - -// TODO: fix these two -void CVoting::ForcevoteKick(int ClientID, const char *pReason) -{ - char aBuf[32]; - if(pReason[0]) - str_format(aBuf, sizeof(aBuf), "kick %d %s", ClientID, pReason); else - str_format(aBuf, sizeof(aBuf), "kick %d", ClientID); - Client()->Rcon(aBuf); + { + char aBuf[32]; + str_format(aBuf, sizeof(aBuf), "%d", ClientID); + Callvote("kick", aBuf, pReason); + } } -void CVoting::ForcevoteOption(int OptionId, const char *pReason) +void CVoting::CallvoteOption(int OptionId, const char *pReason, bool ForceVote) { CVoteOption *pOption = m_pFirst; while(pOption && OptionId >= 0) { if(OptionId == 0) { - Client()->Rcon(pOption->m_aDescription); + if(ForceVote) + { + char aBuf[128]; + str_format(aBuf, sizeof(aBuf), "force_vote option \"%s\" %s", pOption->m_aDescription, pReason); + Client()->Rcon(aBuf); + } + else + Callvote("option", pOption->m_aDescription, pReason); break; } diff --git a/src/game/client/components/voting.h b/src/game/client/components/voting.h index 9687d895..92e4b395 100644 --- a/src/game/client/components/voting.h +++ b/src/game/client/components/voting.h @@ -45,10 +45,8 @@ public: void RenderBars(CUIRect Bars, bool Text); - void CallvoteKick(int ClientID, const char *pReason); - void CallvoteOption(int Option, const char *pReason); - void ForcevoteKick(int ClientID, const char *pReason); - void ForcevoteOption(int Option, const char *pReason); + void CallvoteKick(int ClientID, const char *pReason, bool ForceVote = false); + void CallvoteOption(int Option, const char *pReason, bool ForceVote = false); void Vote(int v); // -1 = no, 1 = yes diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 4d80e0f1..76b51831 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -199,6 +199,7 @@ void CGameClient::OnConsoleInit() 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"); + Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, 0, 0, "Force a voting option"); Console()->Register("clear_votes", "", CFGFLAG_SERVER, 0, 0, "Clears the voting options"); Console()->Register("vote", "r", CFGFLAG_SERVER, 0, 0, "Force a vote to yes/no"); diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 4c236832..476bd20a 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -1045,9 +1045,9 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) str_format(aBuf, sizeof(aBuf), "removed option '%s' '%s'", pOption->m_aDescription, pOption->m_aCommand); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - CHeap *pVoteOptionHeap = new CHeap(); + CHeap *pVoteOptionHeap = new CHeap(); CVoteOption *pVoteOptionFirst = 0; - CVoteOption *pVoteOptionLast = 0; + CVoteOption *pVoteOptionLast = 0; for(CVoteOption *pSrc = pSelf->m_pVoteOptionFirst; pSrc; pSrc = pSrc->m_pNext) { if(pSrc == pOption) @@ -1066,10 +1066,10 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) str_copy(pDst->m_aDescription, pSrc->m_aDescription, sizeof(pDst->m_aDescription)); mem_copy(pDst->m_aCommand, pSrc->m_aCommand, Len+1); - } - - // clean up - delete pSelf->m_pVoteOptionHeap; + } + + // clean up + delete pSelf->m_pVoteOptionHeap; pSelf->m_pVoteOptionHeap = pVoteOptionHeap; pSelf->m_pVoteOptionFirst = pVoteOptionFirst; pSelf->m_pVoteOptionLast = pVoteOptionLast; @@ -1080,6 +1080,61 @@ void CGameContext::ConRemoveVote(IConsole::IResult *pResult, void *pUserData) pSelf->Server()->SendPackMsg(&OptionMsg, MSGFLAG_VITAL, -1); } +void CGameContext::ConForceVote(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + const char *pType = pResult->GetString(0); + const char *pValue = pResult->GetString(1); + const char *pReason = pResult->GetString(2)[0] ? pResult->GetString(2) : "No reason given"; + char aBuf[128] = {0}; + + if(str_comp_nocase(pType, "option") == 0) + { + CVoteOption *pOption = pSelf->m_pVoteOptionFirst; + while(pOption) + { + if(str_comp_nocase(pValue, pOption->m_aDescription) == 0) + { + str_format(aBuf, sizeof(aBuf), "admin forced server option '%s' (%s)", pValue, pReason); + pSelf->SendChatTarget(-1, aBuf); + pSelf->Console()->ExecuteLine(pOption->m_aCommand); + break; + } + + pOption = pOption->m_pNext; + } + + if(!pOption) + { + str_format(aBuf, sizeof(aBuf), "'%s' isn't an option on this server", pValue); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); + return; + } + } + else if(str_comp_nocase(pType, "kick") == 0) + { + int KickID = str_toint(pValue); + if(KickID < 0 || KickID >= MAX_CLIENTS || !pSelf->m_apPlayers[KickID]) + { + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", "Invalid client id to kick"); + return; + } + + if (!g_Config.m_SvVoteKickBantime) + { + str_format(aBuf, sizeof(aBuf), "kick %d %s", KickID, pReason); + pSelf->Console()->ExecuteLine(aBuf); + } + else + { + char aIP[64] = {0}; + pSelf->Server()->GetClientIP(KickID, aIP, sizeof(aIP)); + str_format(aBuf, sizeof(aBuf), "ban %s %d %s", aIP, g_Config.m_SvVoteKickBantime, pReason); + pSelf->Console()->ExecuteLine(aBuf); + } + } +} + void CGameContext::ConClearVotes(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; @@ -1136,6 +1191,7 @@ void CGameContext::OnConsoleInit() Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, ""); Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, ""); + Console()->Register("force_vote", "ss?r", CFGFLAG_SERVER, ConForceVote, this, ""); Console()->Register("clear_votes", "", CFGFLAG_SERVER, ConClearVotes, this, ""); Console()->Register("vote", "r", CFGFLAG_SERVER, ConVote, this, ""); diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 3dc1e99f..bd8140c3 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -55,6 +55,7 @@ class CGameContext : public IGameServer static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData); static void ConAddVote(IConsole::IResult *pResult, void *pUserData); static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData); + 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 ConchainSpecialMotdupdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData); |