From e40e6f38bc3d9ed488b7baa3d6588ff5d0e8076c Mon Sep 17 00:00:00 2001 From: "Marius \"Teelevision\" Neugebauer" Date: Thu, 27 Mar 2014 01:33:59 +0100 Subject: added votebans (known problem: aren't conserved over mapchanges) --- src/game/server/gamecontext.cpp | 72 +++++++++++++++++++++++++++++++++++++++-- src/game/server/gamecontext.h | 4 +++ src/game/server/player.h | 3 ++ 3 files changed, 77 insertions(+), 2 deletions(-) (limited to 'src/game/server') diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index da107b8e..226f9133 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -772,16 +772,25 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID) return; } + char aChatmsg[512]; + + // check voteban + if(pPlayer->m_VoteBannedUntilTick > Server()->Tick()) + { + int left = (pPlayer->m_VoteBannedUntilTick - Server()->Tick()) / Server()->TickSpeed(); + str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d:%02d min until you are allowed to vote again.", left/60, left%60); + SendChatTarget(ClientID, aChatmsg); + return; + } + int Timeleft = pPlayer->m_LastVoteCall + Server()->TickSpeed()*60 - Now; if(pPlayer->m_LastVoteCall && Timeleft > 0) { - char aChatmsg[512] = {0}; str_format(aChatmsg, sizeof(aChatmsg), "You must wait %d seconds before making another vote", (Timeleft/Server()->TickSpeed())+1); SendChatTarget(ClientID, aChatmsg); return; } - char aChatmsg[512] = {0}; char aDesc[VOTE_DESC_LENGTH] = {0}; char aCmd[VOTE_CMD_LENGTH] = {0}; CNetMsg_Cl_CallVote *pMsg = (CNetMsg_Cl_CallVote *)pRawMsg; @@ -1686,6 +1695,61 @@ void CGameContext::ConUnmuteIP(IConsole::IResult *pResult, void *pUserData) } } +void CGameContext::ConVoteban(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + char aBuf[128]; + int CID = pResult->GetInteger(0); + if(CID < 0 || CID >= MAX_CLIENTS || !pSelf->m_apPlayers[CID]) + { + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", "Invalid ClientID"); + return; + } + int time = (pResult->NumArguments() > 1) ? pResult->GetInteger(1) : 300; + pSelf->m_apPlayers[CID]->m_VoteBannedUntilTick = pSelf->Server()->Tick() + time * pSelf->Server()->TickSpeed(); + str_format(aBuf, sizeof(aBuf), "%s has been votebanned for %d:%02d min.", pSelf->Server()->ClientName(CID), time/60, time%60); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); + pSelf->SendChatTarget(-1, aBuf); +} + +void CGameContext::ConUnvoteban(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + char aBuf[128]; + int CID = pResult->GetInteger(0); + if(CID < 0 || CID >= MAX_CLIENTS || !pSelf->m_apPlayers[CID]) + { + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", "Invalid ClientID"); + return; + } + pSelf->m_apPlayers[CID]->m_VoteBannedUntilTick = 0; + str_format(aBuf, sizeof(aBuf), "%s has been un-votebanned.", pSelf->Server()->ClientName(CID)); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); +} + +void CGameContext::ConVotebans(IConsole::IResult *pResult, void *pUserData) +{ + CGameContext *pSelf = (CGameContext *)pUserData; + char aBuf[128]; + char aAddrStr[NETADDR_MAXSTRSIZE]; + int time; + int count = 0; + + for(int i = 0; i < MAX_CLIENTS; i++) + { + if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->m_VoteBannedUntilTick > pSelf->Server()->Tick()) + { + pSelf->Server()->GetClientAddr(i, aAddrStr, sizeof(aAddrStr)); + time = (pSelf->m_apPlayers[i]->m_VoteBannedUntilTick - pSelf->Server()->Tick()) / pSelf->Server()->TickSpeed(); + str_format(aBuf, sizeof(aBuf), "id=%d addr=%s name='%s' time=%d:%02d min", i, aAddrStr, pSelf->Server()->ClientName(i), time/60, time%60); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); + count++; + } + } + str_format(aBuf, sizeof(aBuf), "%d voteban(s)", count); + pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "Server", aBuf); +} + void CGameContext::OnConsoleInit() { m_pServer = Kernel()->RequestInterface(); @@ -1717,6 +1781,10 @@ void CGameContext::OnConsoleInit() Console()->Register("unmuteid", "i", CFGFLAG_SERVER, ConUnmuteID, this, "Unmutes a player by its client id"); Console()->Register("unmuteip", "i", CFGFLAG_SERVER, ConUnmuteIP, this, "Removes a mute by its index"); Console()->Register("mutes", "", CFGFLAG_SERVER, ConMutes, this, "Show all mutes"); + + Console()->Register("voteban", "i?i", CFGFLAG_SERVER, ConVoteban, this, "Voteban a player by id"); + Console()->Register("unvoteban", "i", CFGFLAG_SERVER, ConUnvoteban, this, "Remove voteban on player by id"); + Console()->Register("votebans", "", CFGFLAG_SERVER, ConVotebans, this, "Show all votebans"); Console()->Chain("sv_motd", ConchainSpecialMotdupdate, this); } diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index 5d340613..6a0fd8f9 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -72,6 +72,10 @@ class CGameContext : public IGameServer static void ConUnmuteID(IConsole::IResult *pResult, void *pUserData); static void ConUnmuteIP(IConsole::IResult *pResult, void *pUserData); static void ConMutes(IConsole::IResult *pResult, void *pUserData); + + static void ConVoteban(IConsole::IResult *pResult, void *pUserData); + static void ConUnvoteban(IConsole::IResult *pResult, void *pUserData); + static void ConVotebans(IConsole::IResult *pResult, void *pUserData); CGameContext(int Resetting); void Construct(int Resetting); diff --git a/src/game/server/player.h b/src/game/server/player.h index a19209a8..b7b863d6 100644 --- a/src/game/server/player.h +++ b/src/game/server/player.h @@ -114,6 +114,9 @@ public: int m_CampTick; vec2 m_CampPos; + // voteban system + int m_VoteBannedUntilTick; + private: CCharacter *m_pCharacter; CGameContext *m_pGameServer; -- cgit 1.4.1