about summary refs log tree commit diff
path: root/src/game/server/gamecontext.cpp
diff options
context:
space:
mode:
authorMarius "Teelevision" Neugebauer <marius@teele.eu>2014-03-27 01:33:59 +0100
committerMarius "Teelevision" Neugebauer <marius@teele.eu>2014-03-27 01:33:59 +0100
commite40e6f38bc3d9ed488b7baa3d6588ff5d0e8076c (patch)
treead83c00ff5dcb67786d15a453d25d968dee452cd /src/game/server/gamecontext.cpp
parent05b3c6e55a27accf5d3eafffbdc367e73aac87c0 (diff)
downloadzcatch-e40e6f38bc3d9ed488b7baa3d6588ff5d0e8076c.tar.gz
zcatch-e40e6f38bc3d9ed488b7baa3d6588ff5d0e8076c.zip
added votebans
(known problem: aren't conserved over mapchanges)
Diffstat (limited to 'src/game/server/gamecontext.cpp')
-rw-r--r--src/game/server/gamecontext.cpp72
1 files changed, 70 insertions, 2 deletions
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<IServer>();
@@ -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);
 }