Clamp Spectator ID

This commit is contained in:
Dennis Felsing 2018-12-11 09:23:12 +01:00
parent 7944c9ca75
commit fabd559746
3 changed files with 6 additions and 3 deletions

View file

@ -4,6 +4,7 @@
#define ENGINE_SERVER_H
#include <base/hash.h>
#include <base/math.h>
#include "kernel.h"
#include "message.h"
@ -131,6 +132,7 @@ public:
GetClientInfo(Client, &Info);
if (Info.m_ClientVersion >= VERSION_DDNET_OLD)
return true;
Target = clamp(Target, 0, VANILLA_MAX_CLIENTS-1);
int *pMap = GetIdMap(Client);
if (pMap[Target] == -1)
return false;

View file

@ -1794,7 +1794,9 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
{
CNetMsg_Cl_SetSpectatorMode *pMsg = (CNetMsg_Cl_SetSpectatorMode *)pRawMsg;
if(pMsg->m_SpectatorID != SPEC_FREEVIEW)
pMsg->m_SpectatorID = clamp(pMsg->m_SpectatorID, (int)SPEC_FOLLOW, MAX_CLIENTS-1);
if(pMsg->m_SpectatorID >= 0)
if (!Server()->ReverseTranslate(pMsg->m_SpectatorID, ClientID))
return;
@ -1802,7 +1804,7 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
return;
pPlayer->m_LastSetSpectatorMode = Server()->Tick();
if(pMsg->m_SpectatorID != SPEC_FREEVIEW && (!m_apPlayers[pMsg->m_SpectatorID] || m_apPlayers[pMsg->m_SpectatorID]->GetTeam() == TEAM_SPECTATORS))
if(pMsg->m_SpectatorID >= 0 && (!m_apPlayers[pMsg->m_SpectatorID] || m_apPlayers[pMsg->m_SpectatorID]->GetTeam() == TEAM_SPECTATORS))
SendChatTarget(ClientID, "Invalid spectator id used");
else
pPlayer->m_SpectatorID = pMsg->m_SpectatorID;

View file

@ -509,7 +509,6 @@ CCharacter* CPlayer::ForceSpawn(vec2 Pos)
void CPlayer::SetTeam(int Team, bool DoChatMsg)
{
// clamp the team
Team = GameServer()->m_pController->ClampTeam(Team);
if(m_Team == Team)
return;