Skip to content

Commit

Permalink
abort 'ban vote' when player was banned and 'move to spec' vote when …
Browse files Browse the repository at this point in the history
…player joins the spectators
  • Loading branch information
oy committed Apr 19, 2012
1 parent 900472f commit b8d8859
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/engine/server.h
Expand Up @@ -62,6 +62,7 @@ class IServer : public IInterface
};
virtual void SetRconCID(int ClientID) = 0;
virtual bool IsAuthed(int ClientID) = 0;
virtual bool IsBanned(int ClientID) = 0;
virtual void Kick(int ClientID, const char *pReason) = 0;

virtual void DemoRecorder_HandleAutoStart() = 0;
Expand Down
5 changes: 5 additions & 0 deletions src/engine/server/server.cpp
Expand Up @@ -456,6 +456,11 @@ bool CServer::IsAuthed(int ClientID)
return m_aClients[ClientID].m_Authed;
}

bool CServer::IsBanned(int ClientID)
{
return m_ServerBan.IsBanned(m_NetServer.ClientAddr(ClientID), 0, 0);
}

int CServer::GetClientInfo(int ClientID, CClientInfo *pInfo)
{
dbg_assert(ClientID >= 0 && ClientID < MAX_CLIENTS, "client_id is not valid");
Expand Down
1 change: 1 addition & 0 deletions src/engine/server/server.h
Expand Up @@ -187,6 +187,7 @@ class CServer : public IServer

void SetRconCID(int ClientID);
bool IsAuthed(int ClientID);
bool IsBanned(int ClientID);
int GetClientInfo(int ClientID, CClientInfo *pInfo);
void GetClientAddr(int ClientID, char *pAddrStr, int Size);
const char *ClientName(int ClientID);
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/netban.cpp
Expand Up @@ -243,7 +243,7 @@ typename CNetBan::CBan<T> *CNetBan::CBanPool<T, HashCount>::Get(int Index) const
template<class T>
void CNetBan::MakeBanInfo(const CBan<T> *pBan, char *pBuf, unsigned BuffSize, int Type) const
{
if(pBan == 0)
if(pBan == 0 || pBuf == 0)
{
if(BuffSize > 0)
pBuf[0] = 0;
Expand Down
22 changes: 18 additions & 4 deletions src/game/server/gamecontext.cpp
Expand Up @@ -356,10 +356,16 @@ void CGameContext::SendVoteStatus(int ClientID, int Total, int Yes, int No)

}

void CGameContext::AbortVoteKickOnDisconnect(int ClientID)
void CGameContext::AbortVoteOnDisconnect(int ClientID)
{
if(m_VoteCloseTime && ((!str_comp_num(m_aVoteCommand, "kick ", 5) && str_toint(&m_aVoteCommand[5]) == ClientID) ||
(!str_comp_num(m_aVoteCommand, "set_team ", 9) && str_toint(&m_aVoteCommand[9]) == ClientID)))
if(m_VoteCloseTime && ClientID == m_VoteClientID && (!str_comp_num(m_aVoteCommand, "kick ", 5) ||
!str_comp_num(m_aVoteCommand, "set_team ", 9) || (!str_comp_num(m_aVoteCommand, "ban ", 4) && Server()->IsBanned(ClientID))))
m_VoteCloseTime = -1;
}

void CGameContext::AbortVoteOnTeamChange(int ClientID)
{
if(m_VoteCloseTime && ClientID == m_VoteClientID && !str_comp_num(m_aVoteCommand, "set_team ", 9))
m_VoteCloseTime = -1;
}

Expand Down Expand Up @@ -567,9 +573,15 @@ void CGameContext::OnClientConnected(int ClientID, bool Dummy)
Server()->SendPackMsg(&Msg, MSGFLAG_VITAL, ClientID);
}

void CGameContext::OnClientTeamChange(int ClientID)
{
if(m_apPlayers[ClientID]->GetTeam() == TEAM_SPECTATORS)
AbortVoteOnTeamChange(ClientID);
}

void CGameContext::OnClientDrop(int ClientID, const char *pReason)
{
AbortVoteKickOnDisconnect(ClientID);
AbortVoteOnDisconnect(ClientID);
m_pController->OnPlayerDisconnect(m_apPlayers[ClientID], pReason);
delete m_apPlayers[ClientID];
m_apPlayers[ClientID] = 0;
Expand Down Expand Up @@ -726,6 +738,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
Server()->GetClientAddr(KickID, aAddrStr, sizeof(aAddrStr));
str_format(aCmd, sizeof(aCmd), "ban %s %d Banned by vote", aAddrStr, g_Config.m_SvVoteKickBantime);
}
m_VoteClientID = KickID;
}
else if(str_comp_nocase(pMsg->m_Type, "spectate") == 0)
{
Expand All @@ -750,6 +763,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
str_format(aChatmsg, sizeof(aChatmsg), "'%s' called for vote to move '%s' to spectators (%s)", Server()->ClientName(ClientID), Server()->ClientName(SpectateID), pReason);
str_format(aDesc, sizeof(aDesc), "move '%s' to spectators", Server()->ClientName(SpectateID));
str_format(aCmd, sizeof(aCmd), "set_team %d -1 %d", SpectateID, g_Config.m_SvVoteSpectateRejoindelay);
m_VoteClientID = SpectateID;
}

if(aCmd[0])
Expand Down
5 changes: 4 additions & 1 deletion src/game/server/gamecontext.h
Expand Up @@ -93,7 +93,8 @@ class CGameContext : public IGameServer
void EndVote();
void SendVoteSet(int ClientID);
void SendVoteStatus(int ClientID, int Total, int Yes, int No);
void AbortVoteKickOnDisconnect(int ClientID);
void AbortVoteOnDisconnect(int ClientID);
void AbortVoteOnTeamChange(int ClientID);

int m_VoteCreator;
int64 m_VoteCloseTime;
Expand All @@ -102,6 +103,7 @@ class CGameContext : public IGameServer
char m_aVoteDescription[VOTE_DESC_LENGTH];
char m_aVoteCommand[VOTE_CMD_LENGTH];
char m_aVoteReason[VOTE_REASON_LENGTH];
int m_VoteClientID;
int m_NumVoteOptions;
int m_VoteEnforce;
enum
Expand Down Expand Up @@ -161,6 +163,7 @@ class CGameContext : public IGameServer

virtual void OnClientConnected(int ClientID) { OnClientConnected(ClientID, false); }
void OnClientConnected(int ClientID, bool Dummy);
void OnClientTeamChange(int ClientID);
virtual void OnClientEnter(int ClientID);
virtual void OnClientDrop(int ClientID, const char *pReason);
virtual void OnClientDirectInput(int ClientID, void *pInput);
Expand Down
1 change: 1 addition & 0 deletions src/game/server/gamecontroller.cpp
Expand Up @@ -1047,6 +1047,7 @@ void IGameController::DoTeamChange(CPlayer *pPlayer, int Team, bool DoChatMsg)
pPlayer->m_RespawnDisabled = GetStartRespawnState();
}
OnPlayerInfoChange(pPlayer);
GameServer()->OnClientTeamChange(ClientID);
}

int IGameController::GetStartTeam()
Expand Down

0 comments on commit b8d8859

Please sign in to comment.