From d158267e92db3b240255dc6c20c29a0dea1ce53b Mon Sep 17 00:00:00 2001 From: def Date: Mon, 13 Jan 2014 17:00:49 +0100 Subject: [PATCH] Better broadcasting for spectators --- src/engine/shared/network_server.cpp | 2 +- src/game/server/entities/character.cpp | 8 +++++++- src/game/server/entities/door.cpp | 11 +++++++++++ src/game/server/entities/dragger.cpp | 6 ++++++ src/game/server/entities/gun.cpp | 14 ++++++++++++-- src/game/server/entities/light.cpp | 23 ++++++++++++++++------- src/game/server/entities/pickup.cpp | 12 +++++++++--- src/game/server/entities/plasma.cpp | 4 ++++ 8 files changed, 66 insertions(+), 14 deletions(-) diff --git a/src/engine/shared/network_server.cpp b/src/engine/shared/network_server.cpp index 82ac635d2..7c6665d2b 100644 --- a/src/engine/shared/network_server.cpp +++ b/src/engine/shared/network_server.cpp @@ -69,7 +69,7 @@ int CNetServer::Drop(int ClientID, const char *pReason) int CNetServer::Update() { - int64 Now = time_get(); + //int64 Now = time_get(); for(int i = 0; i < MaxClients(); i++) { m_aSlots[i].m_Connection.Update(); diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 8b2a0c558..89ad0215f 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -1535,6 +1535,8 @@ void CCharacter::HandleTiles(int Index) int z = GameServer()->Collision()->IsTeleport(MapIndex); if(!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons && z && Controller->m_TeleOuts[z-1].size()) { + if (m_Super) + return; m_Core.m_HookedPlayer = -1; m_Core.m_HookState = HOOK_RETRACTED; m_Core.m_TriggeredEvents |= COREEVENT_HOOK_RETRACT; @@ -1545,8 +1547,10 @@ void CCharacter::HandleTiles(int Index) return; } int evilz = GameServer()->Collision()->IsEvilTeleport(MapIndex); - if(evilz && !m_Super && Controller->m_TeleOuts[evilz-1].size()) + if(evilz && Controller->m_TeleOuts[evilz-1].size()) { + if (m_Super) + return; int Num = Controller->m_TeleOuts[evilz-1].size(); m_Core.m_Pos = Controller->m_TeleOuts[evilz-1][(!Num)?Num:rand() % Num]; if (!g_Config.m_SvOldTeleportHook && !g_Config.m_SvOldTeleportWeapons) @@ -1563,6 +1567,8 @@ void CCharacter::HandleTiles(int Index) } if(GameServer()->Collision()->IsCheckTeleport(MapIndex)) { + if (m_Super) + return; // first check if there is a TeleCheckOut for the current recorded checkpoint, if not check previous checkpoints for(int k=m_TeleCheckpoint-1; k >= 0; k--) { diff --git a/src/game/server/entities/door.cpp b/src/game/server/entities/door.cpp index 4ec622e90..225407d84 100644 --- a/src/game/server/entities/door.cpp +++ b/src/game/server/entities/door.cpp @@ -72,13 +72,24 @@ void CDoor::Snap(int SnappingClient) CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); + + if (!pObj) + return; + pObj->m_X = (int) m_Pos.x; pObj->m_Y = (int) m_Pos.y; CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient); int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11; + + if((GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 + || GameServer()->m_apPlayers[SnappingClient]->m_Paused) + && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); + if (Char == 0) return; + if (Char->IsAlive() && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()] && (!Tick)) diff --git a/src/game/server/entities/dragger.cpp b/src/game/server/entities/dragger.cpp index c3bd440fb..ea6b20a29 100644 --- a/src/game/server/entities/dragger.cpp +++ b/src/game/server/entities/dragger.cpp @@ -248,6 +248,12 @@ void CDragger::Snap(int SnappingClient) return; CCharacter * Char = GameServer()->GetPlayerChar(SnappingClient); + + if((GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 + || GameServer()->m_apPlayers[SnappingClient]->m_Paused) + && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); + int Tick = (Server()->Tick() % Server()->TickSpeed()) % 11; if (Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH diff --git a/src/game/server/entities/gun.cpp b/src/game/server/entities/gun.cpp index 7864a3a11..b293330b7 100644 --- a/src/game/server/entities/gun.cpp +++ b/src/game/server/entities/gun.cpp @@ -97,10 +97,20 @@ void CGun::Snap(int SnappingClient) if(NetworkClipped(SnappingClient)) return; - CCharacter * SnapChar = GameServer()->GetPlayerChar(SnappingClient); + CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient); + + if((GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 + || GameServer()->m_apPlayers[SnappingClient]->m_Paused) + && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); + int Tick = (Server()->Tick()%Server()->TickSpeed())%11; - if (SnapChar && SnapChar->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[SnapChar->Team()]) && (!Tick)) return; + if (Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]) && (!Tick)) return; CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem(NETOBJTYPE_LASER, m_ID, 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; diff --git a/src/game/server/entities/light.cpp b/src/game/server/entities/light.cpp index 13bad7ffb..4a3a76cfc 100644 --- a/src/game/server/entities/light.cpp +++ b/src/game/server/entities/light.cpp @@ -108,28 +108,37 @@ void CLight::Snap(int SnappingClient) && NetworkClipped(SnappingClient, m_To)) return; - CCharacter * pSnappingCharacter = GameServer()->GetPlayerChar( - SnappingClient); + CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient); + + if((GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 + || GameServer()->m_apPlayers[SnappingClient]->m_Paused) + && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); + int Tick = (Server()->Tick() % Server()->TickSpeed()) % 6; - if (pSnappingCharacter && pSnappingCharacter->IsAlive() + if (Char && Char->IsAlive() && m_Layer == LAYER_SWITCH - && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pSnappingCharacter->Team()] + && !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()] && (Tick)) return; CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( NETOBJTYPE_LASER, m_ID, sizeof(CNetObj_Laser))); + + if (!pObj) + return; + pObj->m_X = (int) m_Pos.x; pObj->m_Y = (int) m_Pos.y; - if (pSnappingCharacter && pSnappingCharacter->Team() == TEAM_SUPER) + if (Char && Char->Team() == TEAM_SUPER) { pObj->m_FromX = (int) m_Pos.x; pObj->m_FromY = (int) m_Pos.y; } - else if (pSnappingCharacter && m_Layer == LAYER_SWITCH - && GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[pSnappingCharacter->Team()]) + else if (Char && m_Layer == LAYER_SWITCH + && GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]) { pObj->m_FromX = (int) m_To.x; pObj->m_FromY = (int) m_To.y; diff --git a/src/game/server/entities/pickup.cpp b/src/game/server/entities/pickup.cpp index 3a4df732a..92fd82b87 100644 --- a/src/game/server/entities/pickup.cpp +++ b/src/game/server/entities/pickup.cpp @@ -150,11 +150,17 @@ void CPickup::Snap(int SnappingClient) /*if(m_SpawnTick != -1 || NetworkClipped(SnappingClient)) return;*/ - CCharacter * SnapChar = GameServer()->GetPlayerChar(SnappingClient); + CCharacter *Char = GameServer()->GetPlayerChar(SnappingClient); + + if((GameServer()->m_apPlayers[SnappingClient]->GetTeam() == -1 + || GameServer()->m_apPlayers[SnappingClient]->m_Paused) + && GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID != SPEC_FREEVIEW) + Char = GameServer()->GetPlayerChar(GameServer()->m_apPlayers[SnappingClient]->m_SpectatorID); + int Tick = (Server()->Tick()%Server()->TickSpeed())%11; - if (SnapChar && SnapChar->IsAlive() && + if (Char && Char->IsAlive() && (m_Layer == LAYER_SWITCH && - !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[SnapChar->Team()]) + !GameServer()->Collision()->m_pSwitchers[m_Number].m_Status[Char->Team()]) && (!Tick)) return; diff --git a/src/game/server/entities/plasma.cpp b/src/game/server/entities/plasma.cpp index 76e54512b..b5acad9a5 100644 --- a/src/game/server/entities/plasma.cpp +++ b/src/game/server/entities/plasma.cpp @@ -109,6 +109,10 @@ void CPlasma::Snap(int SnappingClient) CNetObj_Laser *pObj = static_cast(Server()->SnapNewItem( NETOBJTYPE_LASER, m_ID, 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;