From 900417b84d015d2440e225282efb6ab71f4acf64 Mon Sep 17 00:00:00 2001 From: fokkonaut <35420825+fokkonaut@users.noreply.github.com> Date: Mon, 26 Sep 2022 19:49:17 +0200 Subject: [PATCH] Send laser objects as DDNetLaser with type (fixes #5885) --- datasrc/network.py | 2 +- src/game/client/components/items.cpp | 4 -- src/game/server/entities/door.cpp | 52 +++++++++++++------- src/game/server/entities/dragger.cpp | 48 ++++++++++++------- src/game/server/entities/dragger_beam.cpp | 38 ++++++++++----- src/game/server/entities/gun.cpp | 37 ++++++++++----- src/game/server/entities/light.cpp | 58 +++++++++++++---------- src/game/server/entities/plasma.cpp | 34 +++++++++---- 8 files changed, 176 insertions(+), 97 deletions(-) diff --git a/datasrc/network.py b/datasrc/network.py index 021392950..f2ecbd491 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -282,7 +282,7 @@ Objects = [ NetIntAny("m_FromX"), NetIntAny("m_FromY"), NetTick("m_StartTick"), - NetIntRange("m_Owner", 0, 'MAX_CLIENTS-1'), + NetIntRange("m_Owner", -1, 'MAX_CLIENTS-1'), NetIntAny("m_Type"), ]), diff --git a/src/game/client/components/items.cpp b/src/game/client/components/items.cpp index 690a72ccc..461bd0488 100644 --- a/src/game/client/components/items.cpp +++ b/src/game/client/components/items.cpp @@ -479,21 +479,18 @@ void CItems::OnRender() if(Inactive && BlinkingLight) continue; Data.m_StartTick = DraggerStartTick; - Data.m_Type = LASERTYPE_FREEZE; } if(pEntEx->m_EntityClass >= ENTITYCLASS_GUN_NORMAL && pEntEx->m_EntityClass <= ENTITYCLASS_GUN_UNFREEZE) { if(Inactive && BlinkingGun) continue; Data.m_StartTick = GunStartTick; - Data.m_Type = pEntEx->m_EntityClass == ENTITYCLASS_GUN_FREEZE ? LASERTYPE_FREEZE : LASERTYPE_DOOR; } if(pEntEx->m_EntityClass >= ENTITYCLASS_DRAGGER_WEAK && pEntEx->m_EntityClass <= ENTITYCLASS_DRAGGER_STRONG) { if(Inactive && BlinkingDragger) continue; Data.m_StartTick = DraggerStartTick; - Data.m_Type = LASERTYPE_DOOR; } if(pEntEx->m_EntityClass == ENTITYCLASS_DOOR) { @@ -503,7 +500,6 @@ void CItems::OnRender() Data.m_From.y = Data.m_To.y; } Data.m_StartTick = Client()->GameTick(g_Config.m_ClDummy); - Data.m_Type = LASERTYPE_DOOR; } } RenderLaser(&Data); diff --git a/src/game/server/entities/door.cpp b/src/game/server/entities/door.cpp index 0926562e7..2e90d2aca 100644 --- a/src/game/server/entities/door.cpp +++ b/src/game/server/entities/door.cpp @@ -45,30 +45,23 @@ void CDoor::Snap(int SnappingClient) if(NetworkClipped(SnappingClient, m_Pos) && NetworkClipped(SnappingClient, m_To)) return; - CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( - NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); - - if(!pObj) - return; - - pObj->m_X = (int)m_Pos.x; - pObj->m_Y = (int)m_Pos.y; - int SnappingClientVersion = GameServer()->GetClientVersion(SnappingClient); CNetObj_EntityEx *pEntData = 0; if(SnappingClientVersion >= VERSION_DDNET_SWITCH) pEntData = static_cast(Server()->SnapNewItem(NETOBJTYPE_ENTITYEX, GetID(), sizeof(CNetObj_EntityEx))); + vec2 From; + int StartTick; + if(pEntData) { pEntData->m_SwitchNumber = m_Number; pEntData->m_Layer = m_Layer; pEntData->m_EntityClass = ENTITYCLASS_DOOR; - pObj->m_FromX = (int)m_To.x; - pObj->m_FromY = (int)m_To.y; - pObj->m_StartTick = 0; + From = m_To; + StartTick = 0; } else { @@ -79,14 +72,39 @@ void CDoor::Snap(int SnappingClient) if(pChr && pChr->Team() != TEAM_SUPER && pChr->IsAlive() && !Switchers().empty() && Switchers()[m_Number].m_aStatus[pChr->Team()]) { - pObj->m_FromX = (int)m_To.x; - pObj->m_FromY = (int)m_To.y; + From = m_To; } else { - pObj->m_FromX = (int)m_Pos.x; - pObj->m_FromY = (int)m_Pos.y; + From = m_Pos; } - pObj->m_StartTick = Server()->Tick(); + StartTick = Server()->Tick(); + } + + if(SnappingClientVersion >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; + + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)From.x; + pObj->m_FromY = (int)From.y; + pObj->m_StartTick = StartTick; + pObj->m_Owner = -1; + pObj->m_Type = LASERTYPE_DOOR; + } + else + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)From.x; + pObj->m_FromY = (int)From.y; + pObj->m_StartTick = StartTick; } } diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index 1836028a3..666559874 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -215,28 +215,40 @@ void CDragger::Snap(int SnappingClient) return; } - CNetObj_Laser *pObjLaser = static_cast(Server()->SnapNewItem( - NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); - - if(!pObjLaser) - return; - - pObjLaser->m_X = (int)m_Pos.x; - pObjLaser->m_Y = (int)m_Pos.y; - pObjLaser->m_FromX = (int)m_Pos.x; - pObjLaser->m_FromY = (int)m_Pos.y; - - if(pEntData) + int StartTick = 0; + if(!pEntData) { - pObjLaser->m_StartTick = 0; - } - else - { - int StartTick = m_EvalTick; + StartTick = m_EvalTick; if(StartTick < Server()->Tick() - 4) StartTick = Server()->Tick() - 4; else if(StartTick > Server()->Tick()) StartTick = Server()->Tick(); - pObjLaser->m_StartTick = StartTick; + } + + if(SnappingClientVersion >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; + + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = StartTick; + pObj->m_Owner = -1; + pObj->m_Type = LASERTYPE_DOOR; + } + else + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = StartTick; } } diff --git a/src/game/server/entities/dragger_beam.cpp b/src/game/server/entities/dragger_beam.cpp index 7ecba8d34..3bc2805af 100644 --- a/src/game/server/entities/dragger_beam.cpp +++ b/src/game/server/entities/dragger_beam.cpp @@ -108,16 +108,6 @@ void CDraggerBeam::Snap(int SnappingClient) { return; } - CNetObj_Laser *pObjLaser = static_cast( - Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); - if(!pObjLaser) - { - return; - } - pObjLaser->m_X = (int)m_Pos.x; - pObjLaser->m_Y = (int)m_Pos.y; - pObjLaser->m_FromX = (int)TargetPos.x; - pObjLaser->m_FromY = (int)TargetPos.y; int StartTick = m_EvalTick; if(StartTick < Server()->Tick() - 4) @@ -128,5 +118,31 @@ void CDraggerBeam::Snap(int SnappingClient) { StartTick = Server()->Tick(); } - pObjLaser->m_StartTick = StartTick; + + if(GameServer()->GetClientVersion(SnappingClient) >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; + + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)TargetPos.x; + pObj->m_FromY = (int)TargetPos.y; + pObj->m_StartTick = StartTick; + pObj->m_Owner = -1; + pObj->m_Type = LASERTYPE_DOOR; + } + else + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)TargetPos.x; + pObj->m_FromY = (int)TargetPos.y; + pObj->m_StartTick = StartTick; + } } diff --git a/src/game/server/entities/gun.cpp b/src/game/server/entities/gun.cpp index 5c997bffd..651a0fa50 100644 --- a/src/game/server/entities/gun.cpp +++ b/src/game/server/entities/gun.cpp @@ -186,19 +186,32 @@ void CGun::Snap(int SnappingClient) return; } - CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( - NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + int StartTick = pEntData ? 0 : m_EvalTick; - if(!pObj) - return; + if(SnappingClientVersion >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; - pObj->m_X = (int)m_Pos.x; - pObj->m_Y = (int)m_Pos.y; - pObj->m_FromX = (int)m_Pos.x; - pObj->m_FromY = (int)m_Pos.y; - - if(pEntData) - pObj->m_StartTick = 0; + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = StartTick; + pObj->m_Owner = -1; + pObj->m_Type = m_Freeze ? LASERTYPE_FREEZE : LASERTYPE_RIFLE; + } else - pObj->m_StartTick = m_EvalTick; + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = StartTick; + } } diff --git a/src/game/server/entities/light.cpp b/src/game/server/entities/light.cpp index 82df42455..908a76bb9 100644 --- a/src/game/server/entities/light.cpp +++ b/src/game/server/entities/light.cpp @@ -129,47 +129,55 @@ void CLight::Snap(int SnappingClient) return; } - CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( - NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); - - if(!pObj) - return; - - pObj->m_X = (int)m_Pos.x; - pObj->m_Y = (int)m_Pos.y; + vec2 From = m_Pos; + int StartTick = 0; if(pChr && pChr->Team() == TEAM_SUPER) { - pObj->m_FromX = (int)m_Pos.x; - pObj->m_FromY = (int)m_Pos.y; + From = m_Pos; } else if(pChr && m_Layer == LAYER_SWITCH && Switchers()[m_Number].m_aStatus[pChr->Team()]) { - pObj->m_FromX = (int)m_To.x; - pObj->m_FromY = (int)m_To.y; + From = m_To; } else if(m_Layer != LAYER_SWITCH) { - pObj->m_FromX = (int)m_To.x; - pObj->m_FromY = (int)m_To.y; - } - else - { - pObj->m_FromX = (int)m_Pos.x; - pObj->m_FromY = (int)m_Pos.y; + From = m_To; } - if(pEntData) + if(!pEntData) { - pObj->m_StartTick = 0; - } - else - { - int StartTick = m_EvalTick; + StartTick = m_EvalTick; if(StartTick < Server()->Tick() - 4) StartTick = Server()->Tick() - 4; else if(StartTick > Server()->Tick()) StartTick = Server()->Tick(); + } + + if(SnappingClientVersion >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; + + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)From.x; + pObj->m_FromY = (int)From.y; + pObj->m_StartTick = StartTick; + pObj->m_Owner = -1; + pObj->m_Type = LASERTYPE_FREEZE; + } + else + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)From.x; + pObj->m_FromY = (int)From.y; pObj->m_StartTick = StartTick; } } diff --git a/src/game/server/entities/plasma.cpp b/src/game/server/entities/plasma.cpp index b95189263..14469e5f3 100644 --- a/src/game/server/entities/plasma.cpp +++ b/src/game/server/entities/plasma.cpp @@ -118,14 +118,30 @@ void CPlasma::Snap(int SnappingClient) if(NetworkClipped(SnappingClient)) return; - CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( - NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); - if(!pObj) - return; + if(GameServer()->GetClientVersion(SnappingClient) >= VERSION_DDNET_MULTI_LASER) + { + CNetObj_DDNetLaser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_DDNETLASER, GetID(), sizeof(CNetObj_DDNetLaser))); + if(!pObj) + return; - pObj->m_X = (int)m_Pos.x; - pObj->m_Y = (int)m_Pos.y; - pObj->m_FromX = (int)m_Pos.x; - pObj->m_FromY = (int)m_Pos.y; - pObj->m_StartTick = m_EvalTick; + pObj->m_ToX = (int)m_Pos.x; + pObj->m_ToY = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = m_EvalTick; + pObj->m_Owner = -1; + pObj->m_Type = m_Freeze ? LASERTYPE_FREEZE : LASERTYPE_RIFLE; + } + else + { + CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, GetID(), sizeof(CNetObj_Laser))); + if(!pObj) + return; + + pObj->m_X = (int)m_Pos.x; + pObj->m_Y = (int)m_Pos.y; + pObj->m_FromX = (int)m_Pos.x; + pObj->m_FromY = (int)m_Pos.y; + pObj->m_StartTick = m_EvalTick; + } }