mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Merge #3430
3430: Filter invalid kill messages r=def- a=Jupeyy Fixes #3429 Also made it a bit safer by checking what the server sends ## Checklist - [x] Tested the change ingame - [ ] Provided screenshots if it is a visual change - [ ] Tested in combination with possibly related configuration options - [ ] Written a unit test if it works standalone, system.c especially - [ ] Considered possible null pointers and out of bounds array indexing - [ ] Changed no physics that affect existing maps - [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional) Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
commit
f6ef42ce0d
|
@ -6,6 +6,7 @@
|
|||
#include <game/generated/client_data.h>
|
||||
#include <game/generated/protocol.h>
|
||||
|
||||
#include "engine/shared/protocol.h"
|
||||
#include "killmessages.h"
|
||||
#include <game/client/animstate.h>
|
||||
#include <game/client/gameclient.h>
|
||||
|
@ -97,16 +98,25 @@ void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
|
|||
|
||||
// unpack messages
|
||||
CKillMsg Kill;
|
||||
Kill.m_aVictimName[0] = '\0';
|
||||
Kill.m_aKillerName[0] = '\0';
|
||||
|
||||
Kill.m_VictimID = pMsg->m_Victim;
|
||||
Kill.m_VictimTeam = m_pClient->m_aClients[Kill.m_VictimID].m_Team;
|
||||
Kill.m_VictimDDTeam = m_pClient->m_Teams.Team(Kill.m_VictimID);
|
||||
str_copy(Kill.m_aVictimName, m_pClient->m_aClients[Kill.m_VictimID].m_aName, sizeof(Kill.m_aVictimName));
|
||||
Kill.m_VictimRenderInfo = m_pClient->m_aClients[Kill.m_VictimID].m_RenderInfo;
|
||||
if(Kill.m_VictimID >= 0 && Kill.m_VictimID < MAX_CLIENTS)
|
||||
{
|
||||
Kill.m_VictimTeam = m_pClient->m_aClients[Kill.m_VictimID].m_Team;
|
||||
Kill.m_VictimDDTeam = m_pClient->m_Teams.Team(Kill.m_VictimID);
|
||||
str_copy(Kill.m_aVictimName, m_pClient->m_aClients[Kill.m_VictimID].m_aName, sizeof(Kill.m_aVictimName));
|
||||
Kill.m_VictimRenderInfo = m_pClient->m_aClients[Kill.m_VictimID].m_RenderInfo;
|
||||
}
|
||||
|
||||
Kill.m_KillerID = pMsg->m_Killer;
|
||||
Kill.m_KillerTeam = m_pClient->m_aClients[Kill.m_KillerID].m_Team;
|
||||
str_copy(Kill.m_aKillerName, m_pClient->m_aClients[Kill.m_KillerID].m_aName, sizeof(Kill.m_aKillerName));
|
||||
Kill.m_KillerRenderInfo = m_pClient->m_aClients[Kill.m_KillerID].m_RenderInfo;
|
||||
if(Kill.m_KillerID >= 0 && Kill.m_KillerID < MAX_CLIENTS)
|
||||
{
|
||||
Kill.m_KillerTeam = m_pClient->m_aClients[Kill.m_KillerID].m_Team;
|
||||
str_copy(Kill.m_aKillerName, m_pClient->m_aClients[Kill.m_KillerID].m_aName, sizeof(Kill.m_aKillerName));
|
||||
Kill.m_KillerRenderInfo = m_pClient->m_aClients[Kill.m_KillerID].m_RenderInfo;
|
||||
}
|
||||
|
||||
Kill.m_Weapon = pMsg->m_Weapon;
|
||||
Kill.m_ModeSpecial = pMsg->m_ModeSpecial;
|
||||
|
@ -125,22 +135,29 @@ void CKillMessages::OnMessage(int MsgType, void *pRawMsg)
|
|||
|
||||
CreateKillmessageNamesIfNotCreated(Kill);
|
||||
|
||||
// add the message
|
||||
m_KillmsgCurrent = (m_KillmsgCurrent + 1) % MAX_KILLMSGS;
|
||||
|
||||
if(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex != -1)
|
||||
bool KillMsgValid = (Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_ColorableRenderSkin.m_Body != -1) || (!Kill.m_VictimRenderInfo.m_CustomColoredSkin && Kill.m_VictimRenderInfo.m_OriginalRenderSkin.m_Body != -1);
|
||||
// if killer != victim, killer must be valid too
|
||||
KillMsgValid &= Kill.m_KillerID == Kill.m_VictimID || ((Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_ColorableRenderSkin.m_Body != -1) || (!Kill.m_KillerRenderInfo.m_CustomColoredSkin && Kill.m_KillerRenderInfo.m_OriginalRenderSkin.m_Body != -1));
|
||||
if(KillMsgValid)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex);
|
||||
m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex = -1;
|
||||
// add the message
|
||||
m_KillmsgCurrent = (m_KillmsgCurrent + 1) % MAX_KILLMSGS;
|
||||
|
||||
if(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex != -1)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex);
|
||||
m_aKillmsgs[m_KillmsgCurrent].m_VictimTextContainerIndex = -1;
|
||||
}
|
||||
|
||||
if(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex != -1)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex);
|
||||
m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex = -1;
|
||||
}
|
||||
|
||||
m_aKillmsgs[m_KillmsgCurrent] = Kill;
|
||||
}
|
||||
|
||||
if(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex != -1)
|
||||
{
|
||||
TextRender()->DeleteTextContainer(m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex);
|
||||
m_aKillmsgs[m_KillmsgCurrent].m_KillerTextContainerIndex = -1;
|
||||
}
|
||||
|
||||
m_aKillmsgs[m_KillmsgCurrent] = Kill;
|
||||
Graphics()->MapScreen(ScreenX0, ScreenY0, ScreenX1, ScreenY1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue